Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
fw:celery [2014/09/04 18:22] alfred [Little tools] |
fw:celery [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 679: | Línea 679: | ||
| ==== Notes ==== | ==== Notes ==== | ||
| * If you want to use print you must set ''CELERY_REDIRECT_STDOUTS'' to ''False''. | * If you want to use print you must set ''CELERY_REDIRECT_STDOUTS'' to ''False''. | ||
| + | |||
| + | === Execute celery task from c# === | ||
| + | <code csharp> | ||
| + | using (var channel = connection.CreateModel()) | ||
| + | { | ||
| + | var guid = Guid.NewGuid().ToString(); | ||
| + | string message = String.Format("{{\"id\": \"{0}\", \"task\": \"my.task\", \"args\": [1, 2]}}", guid); | ||
| + | var body = Encoding.UTF8.GetBytes(message); | ||
| + | |||
| + | IBasicProperties props = channel.CreateBasicProperties(); | ||
| + | props.ContentType = "application/json"; | ||
| + | props.ContentEncoding = "UTF-8"; | ||
| + | //channel.QueueDeclare("celery", true, true, false, null); | ||
| + | channel.BasicPublish("celery", "celery", props, body); | ||
| + | |||
| + | Console.WriteLine(" [x] Sent {0}", message); | ||
| + | } | ||
| + | </code> | ||
| + | When task is: | ||
| + | <code python> | ||
| + | app = Celery('tasks', broker='amqp://guest@192.168.0.100//') | ||
| + | @app.task(name='my.task', ignore_result=True) | ||
| + | def add(a, b): | ||
| + | logger = get_task_logger(__name__) | ||
| + | logger.critical('tralara lalala ' + str(a+b)) | ||
| + | </code> | ||
| + | |||