{"id":16387623,"url":"https://github.com/bitnbytesio/que-it","last_synced_at":"2025-03-23T04:31:29.688Z","repository":{"id":36888962,"uuid":"206293416","full_name":"bitnbytesio/que-it","owner":"bitnbytesio","description":"Background job processing inspired by laravel.","archived":false,"fork":false,"pushed_at":"2023-01-06T14:04:36.000Z","size":375,"stargazers_count":6,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T21:41:34.361Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitnbytesio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-04T10:28:35.000Z","updated_at":"2021-02-16T09:28:09.000Z","dependencies_parsed_at":"2023-01-17T06:46:24.245Z","dependency_job_id":null,"html_url":"https://github.com/bitnbytesio/que-it","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fque-it","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fque-it/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fque-it/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fque-it/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitnbytesio","download_url":"https://codeload.github.com/bitnbytesio/que-it/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244269587,"owners_count":20426254,"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":[],"created_at":"2024-10-11T04:27:01.678Z","updated_at":"2025-03-23T04:31:29.295Z","avatar_url":"https://github.com/bitnbytesio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QUE-IT\n\nBackground job processing inspired by laravel.\n\n[![build status][travis-image]][travis-url]\n[![Coverage Status][codecov-img]][codecov-url]\n[![node version][node-image]][node-url]\n[![NPM version][npm-image]][npm-url]\n[![David deps][david-image]][david-url]\n\n[travis-image]: https://api.travis-ci.org/bitnbytesio/que-it.svg?branch=master\n[travis-url]: https://travis-ci.org/bitnbytesio/que-it?branch=master\n\n[codecov-img]: https://codecov.io/gh/bitnbytesio/que-it/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/bitnbytesio/que-it\n\n[npm-image]: https://img.shields.io/npm/v/que-it.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/que-it\n\n[node-image]: https://img.shields.io/badge/node.js-%3E=_8.16-green.svg?style=flat-square\n[node-url]: http://nodejs.org/download/\n\n[david-image]: https://david-dm.org/bitnbytesio/que-it.svg?style=flat-square\u0026branch=master\n[david-url]: https://david-dm.org/bitnbytesio/que-it?branch=master\n\n## USAGE\n\nSending contact mail example.\n\nYou need to add jobs directory in your projects package.json file.\n\n```json\n{\n  ...\n  \"queit\": {\n    \"jobsDir\": \"path/test/jobs\"\n  }\n}\n```\n\nThen create a job class ContactMail.js in decalred directory.\n\n**Note: File name should match the class name.**\n\n```javascript\nconst { Job } = require('que-it');\n\nclass ContactMail extends Job {\n  constructor({ to }) {\n    this.to = to;\n    /*\n    bull JobOptions\n    this.$opts = {\n      priority: number;\n      delay: number;\n      attempts: number;\n\n      repeat: {\n        tz?: string,\n        endDate?: Date | string | number\n      }\n    };\n    */\n  }\n\n  async run() {\n    // do some fun\n    // SomeMailingPackage.to(this.to).send('Hi!');\n  }\n}\n\nmodule.exports = ContactMail;\n```\n\nIn your controller\n\n```javascript\nconst { dispatch } = require('que-it');\nconst ContactMail = require('path/test/jobs');\n\n// do some code\n\ndispatch(new ContactMail({ to: 'user@example.com' }));\n```\n\ndispatch method will push your job on bull queue.\n\nIn order to start processing queue, you need to start worker as background process with forever/pm2 or what ever process manager you like.\n\nWorker file example.\n\n```javascript\nconst { worker, config } = require('que-it');\n\n// add queue names used in project to worker\nconfig.addQueue('default');\n\n// passing options\n// config.addQueue('default', {redis: {port: 6379, host: '127.0.0.1', password: 'foobared'}});\n\n// will return the object of queues created by worker\n// Single process:\nconst queues = worker.start();\n\n// You can use concurrency as well:\n// const queues = worker.start({ concurrency : 5 });\n// and name your processor\n// const queues = worker.start({ name: 'myProcessor', concurrency : 5 });\n\nqueues['default'].on('completed', () =\u003e {\n  // bull queue event\n});\n```\n\nWorker will create logs directory in current working directory to save job processing logs.\n\n Adding multiple queues\n\n ```javascript\n config.addQueue('default');\n config.addQueue('encoder');\n config.addQueue('mailer');\n ```\n\n Dispatching job on specific queue\n\n```javascript\ndispatch(new ContactMail({ to: 'user@example.com' }).on('mailer'));\n```\n\nProcess job without queueing.\n\n```javascript\nconst { dispatch } = require('que-it');\nconst ContactMail = require('path/test/jobs');\n\n// do some code\n\ndispatch(new ContactMail({ to: 'user@example.com' }).now());\n```\n\n## Configure\n\nChanging default queue drivers.\n\n```javascript\nconst { config } = require('que-it');\n// every job will be processed immediately instead of queue in case of sync drivers\nconfig.set('driver', 'sync');\n\n// queueable driver\n// config.set('driver', 'bull');\n```\n\n**Note: Producer, Worker and Processor each runs as seperate process, on fly config in one does not effect another, considure using file based config.**\n\nCreating config file\n\n```javascript\nconfig.set('driver', 'sync');\nconfig.setJobsDir('./app/jobs');\nconfig.save();\n```\n\nAdding jobs from different directories\n\n```javascript\nconfig.addJob('PasswordReset', './modules/auth/PasswordReset.js');\n```\n\nQue-it considers job as independent module. In case of using database, you have to write a boot file for that.\n\nExample with mongodb:\n\n```javascript\n// boot.js\n// configure env variables\nrequire('dotenv').config();\nconst mongoose = require('mongoose');\n// db connection\nmongoose.connect(process.env.MONGODB, { useNewUrlParser: true }, (err) =\u003e {\n  if (err) {\n    console.error(err);\n  }\n});\n```\n\nYou need to register boot file in package.json of your project.\n\n```json\n{\n  ...\n  \"queit\": {\n    \"jobsDir\": \"path/test/jobs\",\n    \"booter\": \"./boot.js\"\n  }\n}\n```\n\nBy using this boot file, you will be able to use mongoose models in you jobs. Make sure to require used models (populate models also) in job files otherwise mongoose will throw \"MissingSchemaError: Schema hasn't been registered for model\" this error.\n\nFor more configuration, read \u003ca href=\"https://github.com/OptimalBits/bull\"\u003eBull\u003c/a\u003e documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitnbytesio%2Fque-it","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitnbytesio%2Fque-it","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitnbytesio%2Fque-it/lists"}