PHP code example of daanbiesterbos / job-queue-bundle

1. Go to this page and download the library: Download daanbiesterbos/job-queue-bundle 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/ */

    

daanbiesterbos / job-queue-bundle example snippets

 
JMS\JobQueueBundle\JMSJobQueueBundle::class => ['all' => true],

    $em->persist($job);
    $em->flush($job);

    $job->addDependency($job);
    $em->persist($job);
    $em->persist($dependentJob);
    $em->flush();

    $job->add(new DateInterval('PT30M'));
    $job->setExecuteAfter($date);
    $em->persist($job);
    $em->flush();

$job = new Job('a', array(), true, Job::DEFAULT_QUEUE, Job::PRIORITY_HIGH);
$em->persist($job);
$em->flush();

    class MyScheduledCommand extends Command implements CronCommand
    {
        // configure, execute, etc. ...
    
        public function shouldBeScheduled(DateTime $lastRunAt)
        {
            return time() - $lastRunAt->getTimestamp() >= 60; // Executed at most every minute.
        }
    
        public function createCronJob(DateTime $lastRunAt)
        {
            return new Job('my-scheduled-command');
        }
    }
 
    class MyScheduledCommand extends ContainerAwareCommand implements CronCommand
    {
        use ScheduleEveryMinute;
    
        // ...
    }

    class MyJobScheduler implements JobScheduler
    {
        public function getCommands(): array
        {
            return ['my-command'];
        }
    
        public function shouldSchedule($commandName, DateTime $lastRunAt)
        {
            return time() - $lastRunAt->getTimestamp() >= 60; // Executed at most every minute.
        }
    
        public function createJob($commandName, DateTime $lastRunAt)
        {
            return new Job('my-command');
        }
    }