-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Job class not found if using namespace #121
Comments
I think 'My\Job' will fix the issue. |
Tends to do the trick in my code, too. Either way, this is a PHP issue with namespace specifications within strings (they opted to use the string escape character for namespace hierarchy separations, probably rather by accident), rather than an issue with Resque itself (Resque isn't namespace-aware). |
Ok thanks. I will give this a go. |
Unfortunately it still does not find the class...from redis monitor... 1376640721.282846 "SET" "resque:worker:ubuntu:3903:*" "{"queue":"default","run_at":"Fri Aug 16 09:12:01 BST 2013","payload":{"class":"Application\Worker\Example","args":[{"data":"abcd"}],"id":"21775b50a7d3425e22eee88dc4fa6b68"}}" 1376640721.291225 "EXISTS" "resque:job:21775b50a7d3425e22eee88dc4fa6b68:status" |
You have backslash in the end of className I think Application\Worker\Example while writing the name. //Best |
Thanks for your quick response. The backslash at the end I think is the for closing quote ", as I have not put one at the end. class_exists returns true for with single & double backslash prior to enqueue call. |
:) then I have no clue. And I think this problem is specific to your application/implementation. Please close this issue because this is not a bug/feature. |
No problem. Thanks anyway :) |
What's probably happening, then, is that the class you need is loaded on the enqueuing side of your application, but not on the worker side. Keep in mind that a completely separate process (or group of processes, if you use COUNT > 1) is used to run the jobs than the process(es) used to enqueue them. This is the purpose of the APP_INCLUDE environment variable (although I tend to have my application include bin/resque rather than use APP_INCLUDE, but either approach is equally valid): to load in the various code dependencies of your jobs. So, check that the class is available to the workers. You can do this by adding something like |
@eddiejaoude Did you ever figure this out? I really hope so, but if so, this issue really needs to be closed, and only you or Chris can do that. Cheers! |
@danhunsaker I don't think I did, I can't remember, in the end I might have worked around it at the time - it was not a massive issue as it was only a POC project. I can close the issue. |
I'm having the same issue. I autoload my classes with composer like so: {
"require": {
"chrisboulton/php-resque": "dev-master"
},
"autoload": {
"psr-0": {
"SteveEdson\\" : "class"
}
}
}
I can autoload these fine usually, when autoload.php is included, and appropriate |
Just need to make sure that you use the same autoloader in your workers. And then make sure your jobs are defined with the full class name, including namespaces. A |
My worker.php file looks like this <?php
require(__DIR__ . "/vendor/autoload.php");
putenv("VVERBOSE=1");
putenv("LOGGING=1");
putenv("QUEUE=default");
putenv("COUNT=2");
require_once ('vendor/bin/resque'); And I set a job like so: <?php
require("vendor/autoload.php");
Resque::setBackend('localhost:6379');
Resque::enqueue('default', "SteveEdson\\Jobs\\My_Job", $args); Is there anything wrong with either of these setups? Thanks |
Doesn't look like it from here, though I've always been paranoid about PHP name spacing and included the leading backslash. So |
Unfortunately, that does not work either :(
|
Aha! I've figured it out. Its not a PHP Resque issue. The test job I was using was called Sorry about that, thanks you for your time! |
D'oh. Completely missed that. Yes, PSR-0 is set up that way. PSR-4 removes support for underscores as pseudo-namespace separators so they can be used in class names, but we haven't adopted it yet. Glad you got it working! |
my My_queue.php in libraries folder in code ignitor and include it on autoupload.php as well and still getting the issue the i have tried this Resque::enqueue('default', 'application/libraries/My_queue', $timeslot); i have use all thhis while enqueing in queue but still not find my_queue job class please guide me thanks |
You have to either tell Composer to load the file using PSR-4 instead of PSR-0, or rename the class so it doesn't have an underscore ( Don't mix |
@danhunsaker I HAVE renamed the class and it class name now class name is without underscore and still getting the same error no luck |
You've restarted the worker(s) after renaming? Does the class autoload correctly in other parts of your application? Sometimes Composer needs to regenerate the |
When using namespaces, the job class is not found.
I have tried Resque::enqueue('default', 'My\Job', $args); but still no luck.
Any ideas?
�
The text was updated successfully, but these errors were encountered: