Closed optilude closed 9 years ago
Hi @optilude,
assert(self.client.connection.state === 'open');
- This means it's not connecting to AMQP correctly.amqp://guest:guest@localhost:5672//
. (eg, must include, user, pass, host, port, vhost)You don't need to do Meteor.wrapAsync
- running celery-connect
/ celery-shoot
under meteor automatically mixes in task.invokeSync
- which returns a Future
.
eg:
runCeleryTask: function(left, right) {
this.unblock();
var task = Celery.createTask('proj.tasks.add');
try {
return task.invokeSync([left, right]).wait().result;
} catch(e) {
console.error(e);
}
}
Hi!
Those changes cause the following error to appear in the meteor output:
W20150721-00:05:38.519(1)? (STDERR)
W20150721-00:05:38.520(1)? (STDERR) /Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/src/lib/Task.js:245
W20150721-00:05:38.521(1)? (STDERR) status = message.status.toLowerCase();
W20150721-00:05:38.521(1)? (STDERR) ^
W20150721-00:05:38.521(1)? (STDERR) TypeError: Cannot call method 'toLowerCase' of undefined
W20150721-00:05:38.521(1)? (STDERR) at Consumer.CeleryTask_onMessage [as messageHandler] (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/src/lib/Task.js:245:41)
W20150721-00:05:38.521(1)? (STDERR) at Consumer._onContent (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/Consumer.js:341:21)
W20150721-00:05:38.521(1)? (STDERR) at Consumer._onContent (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/Consumer.js:4:61)
W20150721-00:05:38.521(1)? (STDERR) at Connection._onContent (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/Connection.js:580:24)
W20150721-00:05:38.521(1)? (STDERR) at AMQPParser.<anonymous> (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/Connection.js:4:61)
W20150721-00:05:38.522(1)? (STDERR) at AMQPParser.emit (events.js:98:17)
W20150721-00:05:38.522(1)? (STDERR) at AMQPParser.parseContent (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/AMQPParser.js:144:19)
W20150721-00:05:38.522(1)? (STDERR) at AMQPParser.frameEnd (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/AMQPParser.js:87:16)
W20150721-00:05:38.522(1)? (STDERR) at AMQPParser.frame (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/AMQPParser.js:64:21)
W20150721-00:05:38.522(1)? (STDERR) at AMQPParser.header (/Users/maraspeli/.meteor/packages/3stack_celery-shoot/.4.0.1.1gklmv3++os+web.browser+web.cordova/npm/node_modules/celery-shoot/node_modules/amqp-coffee/bin/src/lib/AMQPParser.js:51:21)
=> Exited with code: 8
However, I can see log output in the celery
process that makes it seem like the task is being run.
No result makes it back to the client.
Hmm, can you try setting these in your python celery config
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
That worked!
So, documentation wise, I'd suggest:
$ meteor add 3stack:celery-connect
Celery config (basic adaption of the "next steps" example in the Celery docs):
proj/__init__.py
: empty
proj/celery.py
:
from __future__ import absolute_import
from celery import Celery
app = Celery('proj',
broker='amqp://',
backend='amqp://',
include=['proj.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_TASK_SERIALIZER='json',
CELERY_RESULT_SERIALIZER='json'
)
if __name__ == '__main__':
app.start()
proj/tasks.py
:
from __future__ import absolute_import
from jiraflow.celery import app
@app.task
def add(x, y):
return x + y
@app.task
def mul(x, y):
return x * y
@app.task
def xsum(numbers):
return sum(numbers)
Start RabbitMQ:
$ rabbitmq-server
Start Celery (from the directory where proj
lives):
$ celery -A proj worker -l info
Meteor method example:
Meteor.methods({
runCeleryTask: function(left, right) {
this.unblock();
var task = Celery.createTask('jiraflow.tasks.add');
try {
return task.invokeSync([left, right]).wait().result;
} catch(e) {
console.error(e.stack);
}
}
});
Meteor Startup parameters:
$ env CELERY_BROKER_URL="amqp://guest:guest@localhost:5672//" meteor
Example calling the method:
Meteor.apply("runCeleryTask", [3, 3], {wait: true}, function(err, result) {
console.log("Done");
console.log(err);
console.log(result);
})
Obviously kind of contrived, but it seems to work.
Awesome.
I had a quite go at updating the docs @ https://github.com/3stack-software/meteor-celery-connect
But I'll happily add your outline as a Getting-Started.md
Docs look good!
Would maybe add to the 3stack:celery package a note that it is deprecated?
— Sent from Mailbox
On Tue, Jul 21, 2015 at 9:15 AM, Nathan Muir notifications@github.com wrote:
Awesome. I had a quite go at updating the docs @ https://github.com/3stack-software/meteor-celery-connect
But I'll happily add your outline as a
Getting-Started.md
Reply to this email directly or view it on GitHub: https://github.com/3stack-software/celery-shoot/issues/2#issuecomment-123209031
Hi,
I'm trying to use this in Meteor via
3stack:meteor-connect
.Celery is configured with:
Meteor is started with
env CELERY_BROKER_URL="amqp://" meteor
Method is defined with:
This is called from the client with:
Meteor.apply("runCeleryTask", [3, 3], {wait: true}, function(err, result) { console.log("Done"); console.log(err); console.log(result); })
.This fails with an error in the logs:
I can't really understand what's going on :(
There doesn't seem to be docs explaining how to use it with Meteor, and
3stack:celery
seems to be a different thing now? What am I missing?Martin