Skip to content

Commit e998675

Browse files
Merge pull request #9 from karam-mustafa/v1.2.0
add tasks log
2 parents 485fa9a + e3c7799 commit e998675

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed

docs/commands.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Usage
88
"php artisan make:model ControllerName",
99
// and you can define unlimited commands
1010
);
11-
$process->start();
11+
$process->start()
12+
// if ypu want to see the tasks log,
13+
// you can fetch the tasks lists by calling the function
14+
->getTasts();
1215

1316
```
1417
* Define multiple process and execute them by run function.
@@ -22,7 +25,10 @@ Usage
2225
);
2326

2427
// run function will allows you to get the output from the execution process.
25-
$process->run();
28+
$process->run()
29+
// if ypu want to see the tasks log,
30+
// you can fetch the tasks lists by calling the function
31+
->getTasts();
2632

2733
```
2834
* Add options.
@@ -47,6 +53,9 @@ Usage
4753
);
4854

4955
// run or start your tasks.
50-
$process->start();
56+
$process->start()
57+
// if ypu want to see the tasks log,
58+
// you can fetch the tasks lists by calling the function
59+
->getTasts();
5160

5261
```

docs/php.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ Usage
44
each task must be a callback function as you can see in the below example.
55

66
```shell
7+
8+
// if you are enable the output from the options
9+
// you can see the outputs are printed.
710
$process = \SOS\MultiProcess\Facades\MultiProcessFacade::setTasks(
811
function () {
9-
return \Illuminate\Support\Facades\DB::statement('delete from users where id = 5');
12+
echo 'The first task to run';
1013
}, function () {
11-
return \Illuminate\Support\Facades\DB::statement('delete from users where id = 6');
14+
echo 'The second task to run';
1215
}
1316
);
14-
$process->runPHP();
17+
$process->runPHP()
18+
// if ypu want to see the tasks log,
19+
// you can fetch the tasks lists by calling the function
20+
->getTasts();
1521
```
1622
* Add options.
1723
@@ -21,10 +27,12 @@ each task must be a callback function as you can see in the below example.
2127
// you can change them from the file
2228
// or you can basicly added them from the setter function.
2329
$process = \SOS\MultiProcess\Facades\MultiProcessFacade::setTasks(
24-
"php artisan make:model modelName",
25-
"php artisan make:model ControllerName",
26-
// and you can define unlimited commands
27-
)->setOptions([
30+
function () {
31+
echo 'The first task to run';
32+
}, function () {
33+
echo 'The second task to run';
34+
}
35+
->setOptions([
2836
'timeOut' => 60,
2937
'ideTimeOut' => 60,
3038
'enableOutput' => true,
@@ -35,7 +43,9 @@ each task must be a callback function as you can see in the below example.
3543
);
3644

3745
// run or start your tasks.
38-
$process->start();
39-
46+
$process->runPHP()
47+
// if ypu want to see the tasks log,
48+
// you can fetch the tasks lists by calling the function
49+
->getTasts();
4050
```
4151

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</include>
77
</coverage>
88
<testsuites>
9-
<testsuite name="Spatie Test Suite">
9+
<testsuite name="Test Suite">
1010
<directory>tests</directory>
1111
</testsuite>
1212
</testsuites>

src/Classes/MultiProcess.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,17 @@ private function resolveNotRunningProcess($callback)
296296
foreach ($this->processing as $i => $runningProcess) {
297297
if (!$runningProcess->isRunning()) {
298298

299+
// Remove this task from processing list and run it.
300+
// then register the task log tell that task is now running
301+
// and when the task finished register a new log.
299302
unset($this->processing[$i]);
300303

301304
$this->process(function (Process $process) use ($callback) {
302305
return $callback($process);
303306
});
304307

308+
$this->registerTaskLog($i, 'task is running');
309+
305310
$this->finishTask($i);
306311
}
307312
}
@@ -342,6 +347,8 @@ private function finishTask($key)
342347
if (isset($this->tasks[$key])) {
343348
$this->tasks[$key]['state'] = $this->completedState;
344349
}
350+
351+
$this->registerTaskLog($key, 'task finished');
345352
}
346353

347354
/**
@@ -394,4 +401,21 @@ private function higherOrderRun()
394401
};
395402
}
396403

404+
405+
/**
406+
* when any task change it status, this function must register log that describe the changes.
407+
*
408+
* @param $key
409+
* @param string $string
410+
*
411+
* @author karam mustafa
412+
*/
413+
private function registerTaskLog($key, $string)
414+
{
415+
if (!isset($this->tasks[$key]['log'])) {
416+
$this->tasks[$key]['log'] = [];
417+
}
418+
array_push($this->tasks[$key]['log'], $string);
419+
}
420+
397421
}

0 commit comments

Comments
 (0)