|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console; |
|
4
|
|
|
|
|
5
|
|
|
use App\Model\MailJob\Condition; |
|
6
|
|
|
use Illuminate\Console\Scheduling\Schedule; |
|
7
|
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; |
|
8
|
|
|
|
|
9
|
|
|
class Kernel extends ConsoleKernel |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The Artisan commands provided by your application. |
|
13
|
|
|
* |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $commands = [ |
|
17
|
|
|
'App\Console\Commands\Inspire', |
|
18
|
|
|
'App\Console\Commands\SendReport', |
|
19
|
|
|
'App\Console\Commands\CloseWork', |
|
20
|
|
|
'App\Console\Commands\TicketFetch', |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Define the application's command schedule. |
|
25
|
|
|
* |
|
26
|
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function schedule(Schedule $schedule) |
|
31
|
|
|
{ |
|
32
|
|
|
if (env('DB_INSTALL') == 1) { |
|
33
|
|
|
|
|
34
|
|
|
if ($this->getCurrentQueue() != 'sync') { |
|
35
|
|
|
$schedule->command('queue:listen '.$this->getCurrentQueue().' --sleep 60')->everyMinute(); |
|
36
|
|
|
} |
|
37
|
|
|
$this->execute($schedule, 'fetching'); |
|
38
|
|
|
$this->execute($schedule, 'notification'); |
|
39
|
|
|
$this->execute($schedule, 'work'); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function execute($schedule, $task) |
|
44
|
|
|
{ |
|
45
|
|
|
$condition = new Condition(); |
|
46
|
|
|
$command = $condition->getConditionValue($task); |
|
47
|
|
|
switch ($task) { |
|
48
|
|
|
case 'fetching': |
|
49
|
|
|
$this->getCondition($schedule->command('ticket:fetch'), $command); |
|
50
|
|
|
break; |
|
51
|
|
|
case 'notification': |
|
52
|
|
|
$this->getCondition($schedule->command('report:send'), $command); |
|
53
|
|
|
break; |
|
54
|
|
|
case 'work': |
|
55
|
|
|
$this->getCondition($schedule->command('ticket:close'), $command); |
|
56
|
|
|
break; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getCondition($schedule, $command) |
|
61
|
|
|
{ |
|
62
|
|
|
$condition = $command['condition']; |
|
63
|
|
|
$at = $command['at']; |
|
64
|
|
|
switch ($condition) { |
|
65
|
|
|
case 'everyMinute': |
|
66
|
|
|
$schedule->everyMinute(); |
|
67
|
|
|
break; |
|
68
|
|
|
case 'everyFiveMinutes': |
|
69
|
|
|
$schedule->everyFiveMinutes(); |
|
70
|
|
|
break; |
|
71
|
|
|
case 'everyTenMinutes': |
|
72
|
|
|
$schedule->everyTenMinutes(); |
|
73
|
|
|
break; |
|
74
|
|
|
case 'everyThirtyMinutes': |
|
75
|
|
|
$schedule->everyThirtyMinutes(); |
|
76
|
|
|
break; |
|
77
|
|
|
case 'hourly': |
|
78
|
|
|
$schedule->hourly(); |
|
79
|
|
|
break; |
|
80
|
|
|
case 'daily': |
|
81
|
|
|
$schedule->daily(); |
|
82
|
|
|
break; |
|
83
|
|
|
case 'dailyAt': |
|
84
|
|
|
$this->getConditionWithOption($schedule, $condition, $at); |
|
85
|
|
|
break; |
|
86
|
|
|
case 'weekly': |
|
87
|
|
|
$schedule->weekly(); |
|
88
|
|
|
break; |
|
89
|
|
|
case 'monthly': |
|
90
|
|
|
$schedule->monthly(); |
|
91
|
|
|
break; |
|
92
|
|
|
case 'yearly': |
|
93
|
|
|
$schedule->yearly(); |
|
94
|
|
|
break; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function getConditionWithOption($schedule, $command, $at) |
|
99
|
|
|
{ |
|
100
|
|
|
switch ($command) { |
|
101
|
|
|
case 'dailyAt': |
|
102
|
|
|
$schedule->dailyAt($at); |
|
103
|
|
|
break; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getCurrentQueue() |
|
108
|
|
|
{ |
|
109
|
|
|
$queue = 'database'; |
|
110
|
|
|
$services = new \App\Model\MailJob\QueueService(); |
|
111
|
|
|
$current = $services->where('status', 1)->first(); |
|
|
|
|
|
|
112
|
|
|
if ($current) { |
|
113
|
|
|
$queue = $current->short_name; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $queue; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: