rolies106 / yii-resque

Resque components for Yii, based on php-resque
65 stars 27 forks source link

Can't run a simple job #7

Closed dbanck closed 11 years ago

dbanck commented 11 years ago

I'm facing some problems using yii-resque.

I've created a simple worker:

<?php
/**
* Worker for getting information from facebook about a user
*/
class Worker_GetFacebookUser
{
    public function setUp()
    {
    }

    public function perform()
    {
        var_dump($this);
    }

    public function tearDown()
    {
    }
}

Now I'm trying to create a new job:

$o = app()->resque->createJob('default', 'Worker_GetFacebookUser');

Which produces following log output:

[2013-09-24T16:28:16+00:00] got {"queue":"default","id":"d0c6ae860423e16ad273a3ca5dcd3d32","class":"Worker_GetFacebookUser","args":[[]]}
[2013-09-24T16:28:16+00:00] Processing ID:d0c6ae860423e16ad273a3ca5dcd3d32 in default
<!DOCTYPE html PUBLIC
        "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Internal Server Error</title>

<style type="text/css">
/*<![CDATA[*/
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
/*]]>*/
</style>
</head>

<body>
<h1>Internal Server Error</h1>
<h2>Invalid argument supplied for foreach()</h2>
<p>
An internal error occurred while the Web server was processing your request.
Please contact the webmaster to report this problem.
</p>
<p>
Thank you.
</p>
<div class="version">
2013-09-24 16:28:16 </div>
</body>
</html>

The result inside redis looks like this:

array(7) {
  'failed_at' =>
  string(28) "Tue Sep 24 16:28:16 UTC 2013"
  'payload' =>
  array(3) {
    'class' =>
    string(22) "Worker_GetFacebookUser"
    'args' =>
    array(1) {
      [0] =>
      array(0) {
        ...
      }
    }
    'id' =>
    string(32) "d0c6ae860423e16ad273a3ca5dcd3d32"
  }
  'exception' =>
  string(29) "Resque_Job_DirtyExitException"
  'error' =>
  string(27) "Job exited with exit code 1"
  'backtrace' =>
  array(3) {
    [0] =>
    string(106) "#0 /home/vagrant/backend/current/protected/components/yii-resque/bin/resque(131): Resque_Worker->work('5')"
    [1] =>
    string(118) "#1 /home/vagrant/backend/current/protected/components/yii-resque/bin/resque(103): startWorker('default', 1, NULL, '5')"
    [2] =>
    string(9) "#2 {main}"
  }
  'worker' =>
  string(21) "precise:18861:default"
  'queue' =>
  string(7) "default"
}

What could cause that error? How can I debug further? Due the lack of documentation I don't know where to start.

rolies106 commented 11 years ago

Have you test it with simple echo "something" or var_dump("some text")? And also can you see any detail error in your php log?

dbanck commented 11 years ago

Yes, I've tried that.

I've set log_errors and error_log, but php isn't logging anything else.

rolies106 commented 11 years ago

Hmm... its weird, I've created exactly like yours, I put this on my site controller :

Yii::app()->resque->createJob('default', 'Worker_GetFacebookUser');
die();

I create GetFacebookUser.php and put it in Worker folder :

<?php
/**
* Worker for getting information from facebook about a user
*/
class Worker_GetFacebookUser
{
    public function setUp()
    {
    }

    public function perform()
    {
        var_dump($this);
    }

    public function tearDown()
    {
    }
}

run worker with this command in my root app :

./protected/yiic rresque start

access my site controller from browser and I got this in my log :

[2013-09-24T19:39:33+00:00] got {"queue":"default","id":"56c5dcc6d124e06a2e5252447b4096db","class":"Worker_GetFacebookUser","args":[[]]}
[2013-09-24T19:39:33+00:00] Processing ID:56c5dcc6d124e06a2e5252447b4096db in default
object(Worker_GetFacebookUser)#7 (3) {
  ["job"]=>
  object(Resque_Job)#6 (4) {
    ["queue"]=>
    string(7) "default"
    ["worker"]=>
    object(Resque_Worker)#4 (10) {
      ["logOutput"]=>
      resource(2) of type (stream)
      ["logLevel"]=>
      int(1)
      ["queues":protected]=>
      array(1) {
        [0]=>
        string(1) "*"
      }
      ["hostname":protected]=>
      string(25) "Roliess-MacBook-Pro.local"
      ["shutdown":protected]=>
      bool(false)
      ["paused":protected]=>
      bool(false)
      ["id":protected]=>
      string(32) "Roliess-MacBook-Pro.local:3179:*"
      ["currentJob":protected]=>
      *RECURSION*
      ["child":protected]=>
      int(0)
      ["logger":protected]=>
      NULL
    }
    ["payload"]=>
    array(3) {
      ["class"]=>
      string(22) "Worker_GetFacebookUser"
      ["args"]=>
      array(1) {
        [0]=>
        array(0) {
        }
      }
      ["id"]=>
      string(32) "56c5dcc6d124e06a2e5252447b4096db"
    }
    ["instance":"Resque_Job":private]=>
    *RECURSION*
  }
  ["args"]=>
  array(0) {
  }
  ["queue"]=>
  string(7) "default"
}
[2013-09-24T19:39:33+00:00] done ID:56c5dcc6d124e06a2e5252447b4096db
dbanck commented 11 years ago

That's really weird. Thanks for your effort.

Do you have any idea why the yii_resque_log.log contains html as error message? Since the workers are running on the command line, there shouldn't be involved any web server.

Which PHP version are you using?

dbanck commented 11 years ago

I've edited bin/resque and turned up the error reporting.

The error in detail looks like this: http://download.dbanck.de/yii_error.html

rolies106 commented 11 years ago

what happen if you put die(var_dump(class_exists('Resque_Job_Creator'))); on /home/vagrant/backend/current/protected/components/yii-resque/lib/Resque/Job.php line 154 just for checking the autoloader is running well.

what version of php that you use? mine is 5.4.11

dbanck commented 11 years ago

With the debug statement, the error stays the same, since class_exists is called and causes the error.

Somehow there is no class with that name:

$ git grep 'Resque_Job_Creator'
lib/Resque/Job.php:             if (class_exists('Resque_Job_Creator')) {
lib/Resque/Job.php:                     $this->instance = Resque_Job_Creator::createJob($this->payload['class'], $this->getArguments());
rolies106 commented 11 years ago

Looks the auto loader is not working, can you please try change :

Yii::registerAutoloader(array(new self,'autoload'),true);

to

spl_autoload_register(array(new self, 'autoload'));

in RResqueAutoloader.php line 17

dbanck commented 11 years ago

Same error, just another error message: http://download.dbanck.de/yii_error2.html

There is no file named Resque_Job_Creator.php.

dbanck commented 11 years ago

I've fixed it.

Adding these lines to console.php does the trick:

    ...
    'import' => array(
        'application.models.*',
        'application.helpers.*',
        'application.components.*',
    ),
    ...

Thanks again for your help.