PHP code example of amadeus-m / resque

1. Go to this page and download the library: Download amadeus-m/resque 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/ */

    

amadeus-m / resque example snippets

 php


    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new ResqueBundle\Resque\ResqueBundle(),
            // ...
        );
    }
 php


namespace My;

use ResqueBundle\Resque\Job;

class MyJob extends Job
{
    public function run($args)
    {
        file_put_contents($args['file'], $args['content']);
    }
}
 php


// get resque
$resque = $this->get('resque');

// create your job
$job = new MyJob();
$job->args = array(
    'file'    => '/tmp/file',
    'content' => 'hello',
);

// enqueue your job
$resque->enqueue($job);
 php


// get resque
$resque = $this->get('resque');

// create your job
$job = new MyJob();
$job->args = array(
    'file'    => '/tmp/file',
    'content' => 'hello',
);

// enqueue your job to run at a specific \DateTime or int unix timestamp
$resque->enqueueAt(\DateTime|int $at, $job);

// or

// enqueue your job to run after a number of seconds
$resque->enqueueIn($seconds, $job);

 php


namespace My;

use ResqueBundle\Resque\Job;

class MyJob extends Job
{
    public function __construct()
    {
        $this->queue = 'my_queue';
    }

    public function run($args)
    {
        ...
    }
}
 php


// create your job
$job = new MyJob();
$job->queue = 'my_queue';
 php


namespace My;

use ResqueBundle\Resque\ContainerAwareJob;

class MyJob extends ContainerAwareJob
{
    public function run($args)
    {
        $doctrine = $this->getContainer()->getDoctrine();
        ...
    }
}