PHP code example of quellabs / canvas-scheduler-redis

1. Go to this page and download the library: Download quellabs/canvas-scheduler-redis 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/ */

    

quellabs / canvas-scheduler-redis example snippets


return [
    'queue_driver' => 'redis',
];

$queue = $container->for('redis')->get(QueueInterface::class);

return [
    'scheme'         => 'tcp',
    'host'           => '127.0.0.1',
    'port'           => 6379,
    'queue_name'     => 'default',
    'queue_prefix'   => 'canvas',
    'queue_max_jobs' => 500,
    'queue_timeout'  => 5,
];

use Quellabs\Contracts\Scheduler\QueueableInterface;

class SendEmailJob implements QueueableInterface {

    public function __construct(
        private int    $userId,
        private string $template
    ) {}

    public function handle(): void {
        // Send the email
    }

    public function getPayload(): array {
        return [
            'userId'   => $this->userId,
            'template' => $this->template,
        ];
    }

    public function getTimeout(): int {
        return 30;
    }

    public function getMaxRetries(): int {
        return 3;
    }
}

use Quellabs\Contracts\Scheduler\QueueInterface;

class UserController {

    public function __construct(private QueueInterface $queue) {}

    public function register(Request $request): Response {
        // Handle registration...

        $this->queue->push(new SendEmailJob(
            userId: $user->id,
            template: 'welcome'
        ));

        return new Response('Registered');
    }
}