PHP Resque Worker not working?

1.4k Views Asked by At

I want to use php_resque(https://github.com/chrisboulton/php-resque) for my codeigniter project. This is the function 'test' to create a new job.

public function test() {
    $this->load->library('My_Job');

    Resque::setBackend('localhost:6379');

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

    $token = Resque::enqueue('default', 'My_Job', $args, true);

    $status = new Resque_Job_Status($token);

    Resque::dequeue('default', ['My_Job' => $token]);
}

And this is the worker library code

putenv("VVERBOSE=1");
putenv("LOGGING=1");
putenv("QUEUE=*");
class My_Job {

    public function perform($args) {

        $this->load->model('M_sms');
        $this->M_sms->ins_msg();
    }

}

when i call 'test'(localhost/project_folder/controller/test), the 'perform' function in the worker(My_Job.php) is not loading. And Job status is 1. what is wrong here ?

EDIT

when i used following code to debug

VERBOSE=1 QUEUE=default php resque.php

it says Could not find job class

2

There are 2 best solutions below

0
On BEST ANSWER

In my code, the problem is, the worker do not know the location of job class. As i mentioned above, i am getting status 1 (STATUS_WAITING), which means 'Job is still queued'. This occurred to me because i tried to load the job class as a library in my codeigniter project.

$this->load->library('My_Job');

Now i changed my code according to this tutorial Programe Veryday

This tutorial explain step by step procedure to set up php-resque

0
On

you have to include your application autoloader:

QUEUE=* VVERBOSE=1 REDIS_BACKEND=localhost:9999 APP_INCLUDE=./path/to/loader.php php resque.php

http://kamisama.me/2012/10/12/background-jobs-with-php-and-resque-part-4-managing-worker/