Fix tasks to use proper cron syntax

This commit is contained in:
Dane Everitt 2016-02-28 22:37:58 -05:00
parent 51f4ea7d5d
commit c1301c7190
5 changed files with 20 additions and 39 deletions

View file

@ -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();

View file

@ -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",

View file

@ -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,

View file

@ -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();

View file

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddActiveTaskOption extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tasks', function (Blueprint $table) {
$table->tinyInteger('active')->default(1)->after('server');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tasks', function (Blueprint $table) {
$table->dropColumn('active');
});
}
}