{"id":17766622,"url":"https://github.com/floatdrop/yajob","last_synced_at":"2025-03-15T13:30:52.101Z","repository":{"id":27053659,"uuid":"30519034","full_name":"floatdrop/yajob","owner":"floatdrop","description":"Generator friendly job queue on MongoDB","archived":false,"fork":false,"pushed_at":"2016-11-18T08:03:20.000Z","size":65,"stargazers_count":10,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T01:31:46.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/floatdrop.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":"2015-02-09T04:44:44.000Z","updated_at":"2019-08-19T23:14:50.000Z","dependencies_parsed_at":"2022-06-25T19:03:51.464Z","dependency_job_id":null,"html_url":"https://github.com/floatdrop/yajob","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fyajob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fyajob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fyajob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fyajob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floatdrop","download_url":"https://codeload.github.com/floatdrop/yajob/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243735797,"owners_count":20339530,"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-26T20:33:28.292Z","updated_at":"2025-03-15T13:30:52.094Z","avatar_url":"https://github.com/floatdrop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yajob [![Build Status](https://travis-ci.org/floatdrop/yajob.svg?branch=master)](https://travis-ci.org/floatdrop/yajob)\n\nJob queue on MongoDB. It uses atomic writes to grab jobs and exposes generator friendly API.\n\n__Requirements__:\n\n * NodeJS `\u003e= 4`\n * MongoDB `\u003e= 2.6`\n\n## Usage\n\n```js\nconst yajob = require('yajob');\nconst mails = yajob('localhost/queuedb')\n    .tag('mails');\n\nmails.put({\n    from: 'floatdrop@gmail.com',\n    to: 'nodejs-dev@dev-null.com',\n    body: 'Wow!'\n});\n// =\u003e Promise\n\nfor (var mail of yield mails.take(100)) {\n    yield sendmail(mail);\n}\n```\n\nProcessed jobs removed from queue, when for-loop is ended or broken (either with `break` or exception).\n\n### Skip jobs\n\nIn some cases you will need to skip taken job. To do this pass into generator `false` value:\n\n```js\nconst jobs = yield mails.take(100);\nconst job = jobs.next().value;\n\nif (value === 'Ohnoez') {\n    job.next(false); // Returns Ohnoez back to queue and get next job\n}\n```\n\n### Priorities\n\nBy default, all jobs have priority `0`. You can specify `sort` for queue, in which jobs will be taken:\n\n```js\nconst important = queue.tag('mail').sort({priority: -1});\n```\n\n## API\n\n### Yajob(uri, [options])\n\nReturns instance of queue, that stores data in MongoDB.\n\n##### uri  \nType: `String`  \n\nMongoDB URI string.\n\n##### options  \nType: `Object`  \n\nMongoDB [MongoClient.connect options](http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html).\n\n\n## Methods\n\n### put(attrs, [options])\n\nAdd job to queue. Returns `Promise`.\n\n##### attrs\nType: `Object` / `Array`\n\nData, that will be attached to job. If `attrs` is an `Array` - then every `Object` in `attrs` considered as new job.\n\n### putUnique(attr, [options])\n\nAdd unique by attr job to queue. Returns `Promise`. If job isn't unique promise will be resolved with `{result: {ok: 0, n: 0}}`\n\n##### attr\nType: `Object`\n\nData, that will be attached to job.\n\n##### options\nType: `Object`\n\n * `schedule` - `Date`, when job should be available to `take`\n * `priority` - `Number`, that represents priority of job\n\n### take([count])\n\nReturns `Promise` that resolves to a `Generator`, that will emit jobs one by one.\n\nAfter all jobs are taken from batch - they are considered `done` and removed from queue.\n\n##### count\nType: `Number`  \nDefault: `1`\n\nMaximum number of jobs to take from one batch request.\n\n### remove(attrs)\n\nRemoves jobs, that match `attrs` from queue. Returns `Promise`.\n\n### close([force])\n\nCloses connections to MongoDB.\n\n## Setters\n\n### tag(name)\nDefault: `default`\n\nSets `name` of the MongoDB collection, that will be used to save and get jobs.\n\n### delay(milliseconds)\n\nSets delay for job, that is not scheduled. That is - every job without `schedule` options will be scheduled on `Date() + delay`.\nIf job is failed delay will be used to define new shedule on `Date() + delay`.\n\n### trys(number)\nDefault: `Infinity`\n\nSets maximum job trys, before `failed` status will be assigned.\nDelay between trys is set by `delay(milliseconds)` method.\n\n### sort(order)\n\nSets sort order rule for `take`. Use this, when you need to get jobs, [sorted by priority](#priorities).\n\n### Job status\n\n* `0` - __new__ job, that was just added to queue\n* `1` - __taken__ job, that was assigned to `takenBy` worker\n* `2` - __failed__ job, that has more `attemts` than allowed\n\n## License\n\nMIT © [Vsevolod Strukchinsky](floatdrop@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fyajob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloatdrop%2Fyajob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fyajob/lists"}