wa0x6e / Cake-Resque

Resque plugin for CakePHP : for creating background jobs that can be processed offline later
MIT License
159 stars 56 forks source link

PHP Fatal error: Class 'AppShell' not found #82

Open mwinters0 opened 9 years ago

mwinters0 commented 9 years ago

CakePHP 2.6.1, PHP 5.5.9, Ubuntu 14, cake-resque installed via composer: "kamisama/cake-resque": "4.1.*"

I'm following the tutorial at http://cakeresque.kamisama.me/usecases#sending-emails almost exactly, but receiving the following (abbreviated) error in resque-worker-error.log: PHP Fatal error: Class 'AppShell' not found in [...]/app/Console/Command/EmailQueueWorkerShell.php on line 4

Here are the first 4 lines of EmailQueueWorkerShell.php:

<?php
App::uses('CakeEmail', 'Network/Email');

class EmailQueueWorkerShell extends AppShell {

The worker was started with Console/cake CakeResque.CakeResque start --queue email

Here's the queue code, from within an event listener: CakeResque::enqueue('email', 'EmailQueueWorkerShell', array('sendEmail', $config)); where $config is an Array.

I do have an AppShell in my project's Command directory, with the perform() method added per the tutorial. AppShell is otherwise empty. I also have other shells extending AppShell which I can run without issue.

wa0x6e commented 9 years ago

Do you also have this error when trying to execute the job directly in the shell ?

mwinters0 commented 9 years ago

If I add

    public function main() {
        echo "Yarp\n";
    }

to the EmailQueueWorkerShell I can Console/cake emailQueueWorker and it will echo "Yarp" without complaint.

mwinters0 commented 9 years ago

Here is my full EmailQueueWorkerShell.php:

<?php
App::uses('CakeEmail', 'Network/Email');

class EmailQueueWorkerShell extends AppShell {

    public function main() {
        echo "Yarp\n";
    }

    public function sendEmail() {
        CakeLog::debug('EmailWorker got args: ' . print_r($this->args, true), 'email');
    }
}
wa0x6e commented 9 years ago

Do you have an 'exotic' installation ? Did you install CakePHP via composer too ? Did you install the plugin in another folder ?

mwinters0 commented 9 years ago

I don't think I have anything exotic, but this is a medium-sized app.

Any suggestions of what I could check?

domstubbs commented 9 years ago

I have been setting up CakeResque today and noticed the same problem. In my case I just needed to explicitly load AppShell:

<?php
App::uses('CakeEmail', 'Network/Email');
App::uses('AppShell', 'Console/Command');

class ReportShell extends AppShell {

The example shell in the 'creating job classes' docs does reference this, but it's easy to miss.

Thanks for a great plugin.

mwinters0 commented 9 years ago

Ah yes, that corrected the issue for me. The manual AppShell reference is mentioned at http://cakeresque.kamisama.me/usage#jobs but not http://cakeresque.kamisama.me/usecases#sending-emails . Thanks domstubbs and kamisama. Leaving this open so kamisama can reference it when updating the docs :)

Harrrrry commented 7 years ago

@wa0x6e Do you also have this error when trying to execute the job directly in the shell? yes, I am getting the error when executing the command direct in the shell

Class 'App' not found in