1. Go to this page and download the library: Download daycry/jobs library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daycry / jobs example snippets
use Daycry\Jobs\Jobs;
// Enqueue a spark command to run daily at 02:00 on the "reports" queue, with 3 retries.
$id = Jobs::define('command', 'app:report')
->named('daily-report')
->dailyAt('02:00')
->queue('reports')
->maxRetries(3)
->timeout(120)
->dispatch();
$backend = Jobs::backend('database'); // or Jobs::backend() for the default worker
use Daycry\Jobs\Handlers\JobHandlerInterface;
use Daycry\Jobs\Execution\JobContext;
interface JobHandlerInterface
{
public function handle(JobContext $ctx): mixed;
public function beforeRun(JobContext $ctx): void; // optional lifecycle hook
public function afterRun(JobContext $ctx, $result): void; // optional lifecycle hook
}
use Daycry\Jobs\Handlers\TypedJobHandler;
final class ProcessImport extends TypedJobHandler
{
public function payloadType(): string { return ImportRequest::class; }
protected function run(object $payload): mixed
{
// $payload is an ImportRequest instance hydrated from the queue message.
return 'imported';
}
}