Skip to content

Commit aa0b797

Browse files
committed
Fix error spam in logs due to missing cron month
1 parent 8c7d785 commit aa0b797

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

app/Models/Schedule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ class Schedule extends Model
122122
* Returns the schedule's execution crontab entry as a string.
123123
*
124124
* @return \Carbon\CarbonImmutable
125+
* @throws \Exception
125126
*/
126127
public function getNextRunDate()
127128
{
128129
$formatted = sprintf('%s %s %s %s %s', $this->cron_minute, $this->cron_hour, $this->cron_day_of_month, $this->cron_month, $this->cron_day_of_week);
129130

130131
return CarbonImmutable::createFromTimestamp(
131-
CronExpression::factory($formatted)->getNextRunDate()->getTimestamp()
132+
(new CronExpression($formatted))->getNextRunDate()->getTimestamp()
132133
);
133134
}
134135

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\DB;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
class ForceCronMonthFieldToHaveValueIfMissing extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*
13+
* @return void
14+
*/
15+
public function up()
16+
{
17+
Schema::table('schedules', function (Blueprint $table) {
18+
DB::update("UPDATE `schedules` SET `cron_month` = '*' WHERE `cron_month` = ''");
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
// No down function.
30+
}
31+
}

0 commit comments

Comments
 (0)