Skip to content

Commit d3bb760

Browse files
committed
Adding send method.
1 parent c2d868a commit d3bb760

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Models/MailatorSchedule.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,23 @@ public function shouldSend(): bool
278278
return $this->configurationsPasses() && $this->whenPasses() && $this->eventsPasses();
279279
}
280280

281-
public static function run()
281+
public function execute(): void
282282
{
283-
static::query()
284-
->get()->lazy()
285-
->filter(fn (self $schedule) => $schedule->shouldSend())
286-
->filter(fn (self $schedule) => $schedule->hasCustomAction())
287-
->each(fn (self $schedule) => app($schedule->action)->handle($schedule));
283+
$this->save();
288284

285+
if ($this->hasCustomAction()) {
286+
app($this->action)->handle($this);
287+
} else {
288+
dispatch(new SendMailJob($this));
289+
}
290+
}
291+
292+
public static function run(): void
293+
{
289294
static::query()
290-
->get()->lazy()
295+
->cursor()
291296
->filter(fn (self $schedule) => $schedule->shouldSend())
292-
->filter(fn (self $schedule) => ! $schedule->hasCustomAction())
293-
->each(fn (self $schedule) => dispatch(new SendMailJob($schedule)));
297+
->each(fn (self $schedule) => $schedule->execute());
294298
}
295299

296300
public function hasCustomAction(): bool

0 commit comments

Comments
 (0)