{"id":13583592,"url":"https://github.com/mher/node-celery","last_synced_at":"2025-04-06T21:32:32.012Z","repository":{"id":7377082,"uuid":"8704167","full_name":"mher/node-celery","owner":"mher","description":"Celery client for Node.js","archived":true,"fork":false,"pushed_at":"2020-05-01T09:23:22.000Z","size":103,"stargazers_count":660,"open_issues_count":35,"forks_count":114,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-10-20T11:27:14.417Z","etag":null,"topics":["amqp","background-jobs","celery","javascript","nodejs","queue","rabbitmq","redis","task"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-11T13:39:53.000Z","updated_at":"2024-10-02T15:45:47.000Z","dependencies_parsed_at":"2022-08-20T16:31:03.725Z","dependency_job_id":null,"html_url":"https://github.com/mher/node-celery","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mher%2Fnode-celery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mher%2Fnode-celery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mher%2Fnode-celery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mher%2Fnode-celery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mher","download_url":"https://codeload.github.com/mher/node-celery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223264875,"owners_count":17116228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amqp","background-jobs","celery","javascript","nodejs","queue","rabbitmq","redis","task"],"created_at":"2024-08-01T15:03:37.089Z","updated_at":"2024-11-06T00:30:28.767Z","avatar_url":"https://github.com/mher.png","language":"JavaScript","readme":"# Celery client for Node.js\n\n[![NPM Version](https://img.shields.io/npm/v/node-celery.svg)](https://img.shields.io/npm/v/node-celery.svg)\n[![Downloads](https://img.shields.io/npm/dm/node-celery.svg)](https://img.shields.io/npm/dm/node-celery.svg)\n\nCelery is an asynchronous task/job queue based on distributed\nmessage passing. node-celery allows to queue tasks from Node.js.\nIf you are new to Celery check out http://celeryproject.org/\n\n## Usage\n\nSimple example, included as [examples/hello-world.js](https://github.com/mher/node-celery/blob/master/examples/hello-world.js):\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//',\n\t\tCELERY_RESULT_BACKEND: 'amqp://'\n\t});\n\nclient.on('error', function(err) {\n\tconsole.log(err);\n});\n\nclient.on('connect', function() {\n\tclient.call('tasks.echo', ['Hello World!'], function(result) {\n\t\tconsole.log(result);\n\t\tclient.end();\n\t});\n});\n```\n\n**Note:** When using AMQP as result backend with celery prior to version\n3.1.7 the result queue needs to be non durable or it will fail with a:\nQueue.declare: (406) PRECONDITION_FAILED.\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_TASK_RESULT_DURABLE: false\n\t});\n```\n\nFor RabbitMQ backends, the entire broker options can be passed as an object that is handed off to AMQP.\nThis allows you to specify parameters such as SSL keyfiles, vhost, and connection timeout among others.\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_BROKER_OPTIONS: {\n\t\t\thost: 'localhost',\n\t\t\tport: '5672',\n\t\t\tlogin: 'guest',\n\t\t\tpassword: 'guest',\n\t\t\tauthMechanism: 'AMQPLAIN',\n\t\t\tvhost: '/',\n\t\t\tssl: {\n\t\t\t\tenabled: true,\n\t\t\t\tkeyFile: '/path/to/keyFile.pem',\n\t\t\t\tcertFile: '/path/to/certFile.pem',\n\t\t\t\tcaFile: '/path/to/caFile.pem'\n\t\t\t}\n\t\t},\n\t\tCELERY_RESULT_BACKEND: 'amqp'\n\t});\n```\n\n### ETA\n\nThe ETA (estimated time of arrival) lets you set a specific date and time that is the earliest time at which your task will be executed:\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//',\n\t});\n\nclient.on('connect', function() {\n\tclient.call('send-email', {\n\t\tto: 'to@example.com',\n\t\ttitle: 'sample email'\n\t}, {\n\t\teta: new Date(Date.now() + 60 * 60 * 1000) // an hour later\n\t});\n});\n```\n\n### Expiration\n\nThe expires argument defines an optional expiry time, a specific date and time using Date:\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//',\n\t});\n\nclient.on('connect', function() {\n\tclient.call('tasks.sleep', [2 * 60 * 60], null, {\n\t\texpires: new Date(Date.now() + 60 * 60 * 1000) // expires in an hour\n\t});\n});\n```\n\n### Backends\n\nThe backend is used to store task results. Currently AMQP (RabbitMQ) and Redis backends are supported.\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//',\n\t\tCELERY_RESULT_BACKEND: 'redis://localhost/0'\n\t});\n\nclient.on('connect', function() {\n\tvar result = client.call('tasks.add', [1, 2]);\n\tsetTimeout(function() {\n\t\tresult.get(function(data) {\n\t\t\tconsole.log(data); // data will be null if the task is not finished\n\t\t});\n\t}, 2000);\n});\n```\n\nAMQP backend allows to subscribe to the task result and get it immediately, without polling:\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//',\n\t\tCELERY_RESULT_BACKEND: 'amqp'\n\t});\n\nclient.on('connect', function() {\n\tvar result = client.call('tasks.add', [1, 2]);\n\tresult.on('ready', function(data) {\n\t\tconsole.log(data);\n\t});\n});\n```\n\n### Routing\n\nThe simplest way to route tasks to different queues is using CELERY_ROUTES configuration option:\n\n```javascript\nvar celery = require('node-celery'),\n\tclient = celery.createClient({\n\t\tCELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//',\n\t\tCELERY_ROUTES: {\n\t\t\t'tasks.send_mail': {\n\t\t\t\tqueue: 'mail'\n\t\t\t}\n\t\t}\n\t}),\n\tsend_mail = client.createTask('tasks.send_mail'),\n\tcalculate_rating = client.createTask('tasks.calculate_rating');\n\nclient.on('error', function(err) {\n\tconsole.log(err);\n});\n\nclient.on('connect', function() {\n\tsend_mail.call([], {\n\t\tto: 'to@example.com',\n\t\ttitle: 'hi'\n\t}); // sends a task to the mail queue\n\tcalculate_rating.call([], {\n\t\titem: 1345\n\t}); // sends a task to the default queue\n});\n```\n\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmher%2Fnode-celery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmher%2Fnode-celery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmher%2Fnode-celery/lists"}