Implemented job queue table and the gubbins around it

This commit is contained in:
2022-05-24 16:37:45 +01:00
parent fb24b2ee72
commit 6806291554
11 changed files with 439 additions and 78 deletions

View File

@@ -0,0 +1,68 @@
<?php
/*
* AVSDev UF Worker (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-worker
* @license https://git.avsdev.uk/avsdev/sprinkle-worker/blob/master/LICENSE.md (LGPL-3.0 License)
*/
namespace UserFrosting\Sprinkle\Worker\Database\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Capsule\Manager as DB;
use UserFrosting\Sprinkle\Core\Database\Models\Model;
/**
* Queued Job class
*
* @author Craig Williams (https://avsdev.uk)
*/
class QueuedJob extends Model
{
/**
* @var string The name of the table for the current model.
*/
protected $table = 'queued_jobs';
/**
* Fields that should be mass-assignable when creating a new Organisation.
*
* @var string[]
*/
protected $fillable = [
'job',
'params',
];
/**
* The attributes that should be mutated to dates.
*
* @var string[]
*/
protected $dates = [
'created_at',
'updated_at',
'started_at',
'completed_at',
];
/**
* @var bool Enable timestamps for this class.
*/
public $timestamps = true;
/**
* Dequeues the current model as a job object
*/
public function dequeue()
{
$jobClass = $this->job;
$params = json_decode($this->params, true);
$job = new $jobClass();
$job->setParams($params);
return $job;
}
}