1 | <?php |
||
5 | class LaravelScheduleLogger |
||
6 | { |
||
7 | /** |
||
8 | * Log the start of an event. |
||
9 | * |
||
10 | * @param $command_name |
||
11 | * |
||
12 | * @return mixed |
||
13 | */ |
||
14 | public function start($command_name) |
||
15 | { |
||
16 | return $this->log($command_name); |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * Log the end of an event. |
||
21 | * |
||
22 | * @param $command_name |
||
23 | * |
||
24 | * @return mixed |
||
25 | */ |
||
26 | public function end($command_name) |
||
27 | { |
||
28 | return $this->log($command_name); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Save the event to the database. |
||
33 | * |
||
34 | * @param $command_name |
||
35 | * |
||
36 | * @return mixed |
||
37 | */ |
||
38 | public function log($command_name) |
||
39 | { |
||
40 | $log = Schedulelog::where('end', null)->latest('id', 'DESC')->first(); |
||
41 | |||
42 | if (count($log) == 0) { |
||
43 | return Schedulelog::create([ |
||
44 | 'command_name' => $command_name, |
||
45 | 'start' => microtime(true), |
||
46 | ]); |
||
47 | } else { |
||
48 | $log->end = microtime(true); |
||
49 | $log->save(); |
||
50 | |||
51 | return $log; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Returns the execution time in ms. |
||
57 | * |
||
58 | * @param Schedulelog $log |
||
59 | * |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function getExecutionTime(Schedulelog $log) |
||
66 | } |
||
67 |