Coder Social home page Coder Social logo

Comments (4)

actumn avatar actumn commented on July 22, 2024 1

Sorry for late.

I attached sample codes that I suppose you need.

  • worker
const celery = require("../../dist");

const client = celery.createClient("amqp://", "amqp://");

const url = `s3://s3url_here`
const task = client.createTask('upload-task'); 
const result = task.applyAsync([url]);
result.get().then(data => {
  console.log(data);
  client.disconnect();
});
  • client
const celery = require("../../dist");

const worker = celery.createWorker("amqp://", "amqp://");
worker.register('upload-task', (url) => {
  console.log('s3upload URL here: ', url);
  return url;
});
worker.start();

Just try executing node client.js after executing node worker.js.
Then the console output would be below.

  • node worker.js
celery.node worker start...
registed task: upload-task
celery.node Received task: upload-task[a3ac8ec8-7924-4db1-a61a-e2a906efe797], args: s3://s3url_here, kwargs: {}
s3upload url:  s3://s3url_here
celery.node Task upload-task[a3ac8ec8-7924-4db1-a61a-e2a906efe797] succeeded in 0.000260853s: s3://s3url_here
  • node client.js
s3://s3url_here

If you have any questions, I answer it as soon as possible.
Thank you

from celery.node.

actumn avatar actumn commented on July 22, 2024

Hi.
I'm so glad that you're planning to use it :)

If you want to use with RabbitMQ, try below.

  • Worker-side
const celery = require("celery-node");

const worker = celery.createWorker("amqp://", "amqp://", "queue_name");
worker.register("tasks.add", (a, b) => a + b);
worker.start();
  • Client-side
const celery = require("celery-node");

const client = celery.createClient("amqp://", "amqp://", "queue_name");

const task = client.createTask("tasks.add");
const result = task.applyAsync([1, 2]);
result.get().then(data => {
  console.log(data);
  client.disconnect();
});

I hope this could be helpful.

from celery.node.

ardian-c avatar ardian-c commented on July 22, 2024

Thanks, I can now connect to a particular queue however I don't understand how to read its payload and send that as a parameter to the task.

In your example you create a task tasks.add, and then send params [1,2], but I want to get the payload from a queue, which in my case is a file url in S3, and then pass that url to the worker, ideally in this way node worker.js --url some_file.csv.

I see the implementation in the official documentation which uses channel.consume to read the messages from queue, is there an equivalent with this library?

from celery.node.

ardian-c avatar ardian-c commented on July 22, 2024

Thank you, that's similar to what I did.

from celery.node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.