diff --git a/README.md b/README.md index 914ba2d0..f8eefb98 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,7 @@ Full documentation: https://dereuromark.github.io/cakephp-queue/ ## Cronjob based background scheduling If you are looking for scheduling certain background jobs: This plugin works flawlessly with [QueueScheduler plugin](https://github.com/dereuromark/cakephp-queue-scheduler). + +## FORK NOTES +This fork is to add a few features to the original plugin: +- Add a `QueueProcesses.job_type` column and sets it to the job type when a job is created diff --git a/config/Migrations/20191319000002_MigrationQueueRename.php b/config/Migrations/20191319000002_MigrationQueueRename.php new file mode 100644 index 00000000..81521807 --- /dev/null +++ b/config/Migrations/20191319000002_MigrationQueueRename.php @@ -0,0 +1,31 @@ +table('queued_jobs'); + $table->renameColumn('job_type', 'job_task') + ->update(); + + $table->changeColumn('job_task', 'string', [ + 'length' => 90, + 'null' => false, + 'default' => null, + 'encoding' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + ])->update(); + } + +} diff --git a/src/Model/Entity/QueuedJob.php b/src/Model/Entity/QueuedJob.php index 7c69a84c..6e02421d 100644 --- a/src/Model/Entity/QueuedJob.php +++ b/src/Model/Entity/QueuedJob.php @@ -11,6 +11,7 @@ * @property array|null $data * @property string|null $data_string Virtual property from JsonableBehavior * @property string|null $job_group + * @property string|null $job_type * @property string|null $reference * @property \Cake\I18n\DateTime $created * @property \Cake\I18n\DateTime|null $notbefore diff --git a/src/Model/Table/QueueProcessesTable.php b/src/Model/Table/QueueProcessesTable.php index bfb500d3..6520e16f 100644 --- a/src/Model/Table/QueueProcessesTable.php +++ b/src/Model/Table/QueueProcessesTable.php @@ -70,6 +70,7 @@ public function initialize(array $config): void { $this->addBehavior('Timestamp'); + $this->hasOne('CurrentQueuedJobs', [ 'className' => 'Queue.QueuedJobs', 'foreignKey' => 'workerkey', @@ -108,6 +109,9 @@ public function validationDefault(Validator $validator): Validator { 'message' => 'Too many workers running. Check your `Queue.maxworkers` config.', ]); + $validator->notEmptyString('job_type'); + + return $validator; } @@ -144,10 +148,11 @@ public function findActive(): SelectQuery { /** * @param string $pid * @param string $key + * @param string $jobType * * @return int */ - public function add(string $pid, string $key): int { + public function add(string $pid, string $key, string $jobType): int { $server = $this->buildServerString(); // Evict any stale row holding our (pid, server) slot. Common after @@ -167,6 +172,7 @@ public function add(string $pid, string $key): int { 'pid' => $pid, 'server' => $server, 'workerkey' => $key, + 'job_type' => $jobType ]; $queueProcess = $this->newEntity($data);