完善 任务调度

This commit is contained in:
iVampireSP.com 2022-09-03 13:22:40 +08:00
parent 80053c35aa
commit db9b20c49b
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 51 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console;
use App\Jobs\ClearTasks;
use App\Jobs\Remote;
use App\Jobs\HostCost;
use App\Jobs\UserSave;
@ -27,6 +28,9 @@ protected function schedule(Schedule $schedule)
$schedule->job(new Remote\PushHost())->everyMinute()->onOneServer();
$schedule->job(new Remote\PushWorkOrder())->everyMinute()->onOneServer();
$schedule->job(new ClearTasks())->weekly();
}
/**

40
app/Jobs/ClearTasks.php Normal file
View File

@ -0,0 +1,40 @@
<?php
namespace App\Jobs;
use App\Models\User\Task;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ClearTasks implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
// 删除所有状态不为 pending 的任务
Task::where('status', '!=', 'pending')->delete();
}
}

View File

@ -63,5 +63,12 @@ protected static function boot()
}
});
// updateing
static::updating(function ($model) {
if ($model->progress == 100) {
$model->status = 'done';
}
});
}
}