From c1301c71901a78caf0980fa0f5c2f2105dd5f26d Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 28 Feb 2016 22:37:58 -0500 Subject: [PATCH] Fix tasks to use proper cron syntax --- app/Jobs/SendScheduledTask.php | 11 ++++++- composer.json | 3 +- config/app.php | 1 + .../2016_02_27_163411_add_tasks_table.php | 13 ++++---- ...16_02_27_190725_add_active_task_option.php | 31 ------------------- 5 files changed, 20 insertions(+), 39 deletions(-) delete mode 100644 database/migrations/2016_02_27_190725_add_active_task_option.php diff --git a/app/Jobs/SendScheduledTask.php b/app/Jobs/SendScheduledTask.php index 2fff42094..d8348a583 100644 --- a/app/Jobs/SendScheduledTask.php +++ b/app/Jobs/SendScheduledTask.php @@ -30,6 +30,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use DB; use Carbon; +use Cron; use Pterodactyl\Models; use Pterodactyl\Repositories\Daemon\CommandRepository; use Pterodactyl\Repositories\Daemon\PowerRepository; @@ -94,9 +95,17 @@ class SendScheduledTask extends Job implements ShouldQueue ]); throw $ex; } finally { + $cron = Cron::factory(sprintf('%s %s %s %s %s %s', + $this->task->minute, + $this->task->hour, + $this->task->day_of_month, + $this->task->month, + $this->task->day_of_week, + $this->task->year + )); $this->task->fill([ 'last_run' => $time, - 'next_run' => $time->addMonths($this->task->month)->addWeeks($this->task->week)->addDays($this->task->day)->addHours($this->task->hour)->addMinutes($this->task->minute)->addSeconds($this->task->second), + 'next_run' => $cron->getNextRunDate(), 'queued' => 0 ]); $this->task->save(); diff --git a/composer.json b/composer.json index da8a9b577..898d89da0 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "s1lentium/iptools": "^1.0", "edvinaskrucas/settings": "^2.0", "igaster/laravel-theme": "^1.1", - "nesbot/carbon": "^1.21" + "nesbot/carbon": "^1.21", + "mtdowling/cron-expression": "^1.1" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/config/app.php b/config/app.php index 559b48fb8..7d92f1697 100644 --- a/config/app.php +++ b/config/app.php @@ -183,6 +183,7 @@ return [ 'Carbon' => Carbon\Carbon::class, 'Config' => Illuminate\Support\Facades\Config::class, 'Cookie' => Illuminate\Support\Facades\Cookie::class, + 'Cron' => Cron\CronExpression::class, 'Crypt' => Illuminate\Support\Facades\Crypt::class, 'DB' => Illuminate\Support\Facades\DB::class, 'Debugbar' => Barryvdh\Debugbar\Facade::class, diff --git a/database/migrations/2016_02_27_163411_add_tasks_table.php b/database/migrations/2016_02_27_163411_add_tasks_table.php index c05fb1be4..2cdaa30b6 100644 --- a/database/migrations/2016_02_27_163411_add_tasks_table.php +++ b/database/migrations/2016_02_27_163411_add_tasks_table.php @@ -15,15 +15,16 @@ class AddTasksTable extends Migration Schema::create('tasks', function (Blueprint $table) { $table->increments('id'); $table->integer('server')->unsigned(); + $table->tinyInteger('active')->default(1); $table->string('action'); $table->text('data'); $table->tinyInteger('queued')->unsigned()->default(0); - $table->integer('month')->default(0); - $table->integer('week')->default(0); - $table->integer('day')->default(0); - $table->integer('hour')->default(0); - $table->integer('minute')->default(0); - $table->integer('second')->default(0); + $table->string('year')->default('*'); + $table->string('day_of_week')->default('*'); + $table->string('month')->default('*'); + $table->string('day_of_month')->default('*'); + $table->string('hour')->default('*'); + $table->string('minute')->default('*'); $table->timestamp('last_run'); $table->timestamp('next_run'); $table->timestamps(); diff --git a/database/migrations/2016_02_27_190725_add_active_task_option.php b/database/migrations/2016_02_27_190725_add_active_task_option.php deleted file mode 100644 index d63111424..000000000 --- a/database/migrations/2016_02_27_190725_add_active_task_option.php +++ /dev/null @@ -1,31 +0,0 @@ -tinyInteger('active')->default(1)->after('server'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('tasks', function (Blueprint $table) { - $table->dropColumn('active'); - }); - } -}