|
2 | 2 |
|
3 | 3 | namespace Studio\Totem;
|
4 | 4 |
|
5 |
| -use Closure; |
6 | 5 | use Cron\CronExpression;
|
7 | 6 | use Illuminate\Database\Eloquent\Model;
|
| 7 | +use Studio\Totem\Traits\HasFrequencies; |
8 | 8 | use Illuminate\Notifications\Notifiable;
|
9 |
| -use Illuminate\Console\Scheduling\ManagesFrequencies; |
10 | 9 |
|
11 | 10 | class Task extends Model
|
12 | 11 | {
|
13 |
| - use Notifiable, ManagesFrequencies; |
14 |
| - |
15 |
| - /** |
16 |
| - * The array of filter callbacks. |
17 |
| - * |
18 |
| - * @var array |
19 |
| - */ |
20 |
| - protected $filters = []; |
21 |
| - |
22 |
| - /** |
23 |
| - * The array of reject callbacks. |
24 |
| - * |
25 |
| - * @var array |
26 |
| - */ |
27 |
| - protected $rejects = []; |
| 12 | + use Notifiable, HasFrequencies; |
28 | 13 |
|
29 | 14 | /**
|
30 | 15 | * The attributes that are mass assignable.
|
@@ -75,16 +60,6 @@ public function getUpcomingAttribute()
|
75 | 60 | return CronExpression::factory($this->getCronExpression())->getNextRunDate()->format('Y-m-d H:i:s');
|
76 | 61 | }
|
77 | 62 |
|
78 |
| - /** |
79 |
| - * Frequencies Relation. |
80 |
| - * |
81 |
| - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
82 |
| - */ |
83 |
| - public function frequencies() |
84 |
| - { |
85 |
| - return $this->hasMany(Frequency::class, 'task_id', 'id')->with('parameters'); |
86 |
| - } |
87 |
| - |
88 | 63 | /**
|
89 | 64 | * Results Relation.
|
90 | 65 | *
|
@@ -124,80 +99,4 @@ public function routeNotificationForSlack()
|
124 | 99 | {
|
125 | 100 | return $this->notification_slack_webhook;
|
126 | 101 | }
|
127 |
| - |
128 |
| - /** |
129 |
| - * Generate a cron expression from frequencies. |
130 |
| - * |
131 |
| - * @return string |
132 |
| - */ |
133 |
| - public function getCronExpression() |
134 |
| - { |
135 |
| - if (! $this->expression) { |
136 |
| - $this->expression = '* * * * * *'; |
137 |
| - |
138 |
| - foreach ($this->frequencies as $frequency) { |
139 |
| - call_user_func_array([$this, $frequency->interval], $frequency->parameters->pluck('value')->toArray()); |
140 |
| - } |
141 |
| - } |
142 |
| - |
143 |
| - return $this->expression; |
144 |
| - } |
145 |
| - |
146 |
| - /** |
147 |
| - * Get the mutex name for the scheduled task. |
148 |
| - * |
149 |
| - * @return string |
150 |
| - */ |
151 |
| - public function getMutexName() |
152 |
| - { |
153 |
| - return 'logs'.DIRECTORY_SEPARATOR.'schedule-'.sha1($this->expression.$this->command); |
154 |
| - } |
155 |
| - |
156 |
| - /** |
157 |
| - * Determine if the filters pass for the event. |
158 |
| - * |
159 |
| - * @param \Illuminate\Contracts\Foundation\Application $app |
160 |
| - * @return bool |
161 |
| - */ |
162 |
| - public function filtersPass($app) |
163 |
| - { |
164 |
| - foreach ($this->filters as $callback) { |
165 |
| - if (! $app->call($callback)) { |
166 |
| - return false; |
167 |
| - } |
168 |
| - } |
169 |
| - |
170 |
| - foreach ($this->rejects as $callback) { |
171 |
| - if ($app->call($callback)) { |
172 |
| - return false; |
173 |
| - } |
174 |
| - } |
175 |
| - |
176 |
| - return true; |
177 |
| - } |
178 |
| - |
179 |
| - /** |
180 |
| - * Register a callback to further filter the schedule. |
181 |
| - * |
182 |
| - * @param \Closure $callback |
183 |
| - * @return $this |
184 |
| - */ |
185 |
| - public function when(Closure $callback) |
186 |
| - { |
187 |
| - $this->filters[] = $callback; |
188 |
| - |
189 |
| - return $this; |
190 |
| - } |
191 |
| - |
192 |
| - /** |
193 |
| - * Schedule the event to run between start and end time. |
194 |
| - * |
195 |
| - * @param string $startTime |
196 |
| - * @param string $endTime |
197 |
| - * @return $this |
198 |
| - */ |
199 |
| - public function between($startTime, $endTime) |
200 |
| - { |
201 |
| - return $this->when($this->inTimeInterval($startTime, $endTime)); |
202 |
| - } |
203 | 102 | }
|
0 commit comments