Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
16 / 16 |
ProcessFactoryStatusModel | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
16 / 16 |
createProcessStatus | |
100.00% |
1 / 1 |
1 | |
100.00% |
7 / 7 |
|||
activeProcessStatus | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
updateProcessStatus | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
deleteProcessStatus | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
getCurrentTry | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\AsyncProcessFactory\Traits; |
4 | |
5 | use Illuminate\Support\Facades\Log; |
6 | use Qmp\Laravel\AsyncProcessFactory\Model\ProcessStatus; |
7 | |
8 | trait ProcessFactoryStatusModel |
9 | { |
10 | |
11 | /** |
12 | * Undocumented variable |
13 | * |
14 | * @var [type] |
15 | */ |
16 | protected $id; |
17 | |
18 | |
19 | /** |
20 | * Store a newx proces |
21 | * |
22 | * @param string $command |
23 | * @return void |
24 | */ |
25 | protected function createProcessStatus(string $command): void |
26 | { |
27 | $this->id = bin2hex(random_bytes(6)); |
28 | |
29 | $values = [ |
30 | 'id' => $this->id, |
31 | 'command' => $command, |
32 | 'try' => 1, |
33 | 'options' => null, |
34 | 'pid' => null, |
35 | 'active' => 0 |
36 | ]; |
37 | |
38 | ProcessStatus::create($values); |
39 | } |
40 | |
41 | protected function activeProcessStatus() |
42 | { |
43 | return ProcessStatus::where('id', $this->id)->update([ |
44 | 'active' => 1 |
45 | ]); |
46 | } |
47 | |
48 | /** |
49 | * Update the given proess |
50 | * |
51 | * @param integer $pid |
52 | * @param array $options |
53 | * @return boolean |
54 | */ |
55 | protected function updateProcessStatus(int $pid, array $options): bool |
56 | { |
57 | return ProcessStatus::where('id', $this->id)->update([ |
58 | 'pid' => $pid, |
59 | 'options' => $options |
60 | ]); |
61 | } |
62 | |
63 | /**Delete the given proess |
64 | * |
65 | * @return void |
66 | */ |
67 | protected function deleteProcessStatus(): void |
68 | { |
69 | ProcessStatus::find($this->id)->delete(); |
70 | Log::debug(var_export('deleteProcessStatus : ' . $this->id, true)); |
71 | } |
72 | |
73 | /** |
74 | * Undocumented function |
75 | * |
76 | * @return integer |
77 | */ |
78 | protected function getCurrentTry(): int |
79 | { |
80 | return ProcessStatus::find($this->id)->try; |
81 | } |
82 | } |