arakaki-yuji / backjob
it is a job queue library
Installs: 1 541
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- microsoft/azure-storage-queue: ^1.3.0
Requires (Dev)
- phpunit/phpunit: ^7.5
README
a job queue library that use Azure Queue Storage .
Installation
Include arakaki-yuji/backjob in your project, by adding it to your composer.json file.
{ "require": { "arakaki-yuji/backjob": "^0.0.5" } }
Usage
Define your own Job
class CustomJob extends \Backjob\Job { /** * You must define a run method. * this method is called when dequeued and run */ public function run() { $msg = $this->params['message']; return $msg; } /** * this method is optional. * if you define success method, it is called after run method successed. */ public function success() { return 'success job'; } /** * this method is optional. * if you define fail method, it is called after run method failed. */ public function fail() { return 'success job'; } }
Enqueue, dequeue and run a job.
setup a backjob instance.
$backjob = new \Backjob\Backjob::factory($storageAccountName, $queueName, $accessKey);
Enqueue a job
$params = ['message' => 'Hello Backjob']; $job = CustomeJob::makeJob($params); $backjob->queue($job);
Dequeue and run a job.
$backjob = new \Backjob\Backjob::factory($storageAccountName, $queueName, $accessKey); $backjob->run(); // => 'Hello Backjob'