user1740664
user1740664

Reputation: 3

How can I define a job in php resque for redis?

I am new for redis and currently I am using PHP resque for redis. How can I define a job in php resque?

Upvotes: 0

Views: 551

Answers (2)

greenmindpdx
greenmindpdx

Reputation: 21

This has changed in the newest version of PHP-resque, released 13 October 2012. According to the changelog, "Wrap job arguments in an array to improve compatibility with ruby resque."

which means if you've upgraded to PHP-Resque 1.2 you will access jobs from $args[0].

Upvotes: 2

Avinash Dubey
Avinash Dubey

Reputation: 128

Queueing Jobs

Jobs are queued as follows:

require_once 'lib/Resque.php';

// Required if redis is located elsewhere
Resque::setBackend('localhost:6379');

$args = array(
    'name' => 'Chris'
);

Resque::enqueue('default', 'My_Job', $args); Defining Jobs

Each job should be in it's own class, and include a perform method.

class My_Job
{
    public function perform()
    {
        // Work work work
        echo $this->args['name'];
    }
}

When the job is run, the class will be instantiated and any arguments will be set as an array on the instantiated object, and are accessible via $this->args.

Any exception thrown by a job will result in the job failing - be careful here and make sure you handle the exceptions that shouldn't result in a job failing.

Upvotes: 0

Related Questions