{"id":19128825,"url":"https://github.com/peerlibrary/meteor-classy-job","last_synced_at":"2025-05-06T00:11:31.108Z","repository":{"id":68281802,"uuid":"47497032","full_name":"peerlibrary/meteor-classy-job","owner":"peerlibrary","description":"Class-based wrapper around job collection","archived":false,"fork":false,"pushed_at":"2016-11-10T11:01:06.000Z","size":18,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-19T12:42:23.969Z","etag":null,"topics":["meteor","meteor-package"],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"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/peerlibrary.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-06T13:06:44.000Z","updated_at":"2018-01-15T11:39:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"1dbcef92-3f62-4873-b384-32218d737eb7","html_url":"https://github.com/peerlibrary/meteor-classy-job","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/peerlibrary%2Fmeteor-classy-job","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-classy-job/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-classy-job/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerlibrary%2Fmeteor-classy-job/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peerlibrary","download_url":"https://codeload.github.com/peerlibrary/meteor-classy-job/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596422,"owners_count":21773845,"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":["meteor","meteor-package"],"created_at":"2024-11-09T06:05:46.600Z","updated_at":"2025-05-06T00:11:31.098Z","avatar_url":"https://github.com/peerlibrary.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Classy Job\n==========\n\nA class-based wrapper around [job collection](https://github.com/vsivsi/meteor-job-collection),\na powerful and easy to use job manager for Meteor.\n\nAdding this package to your [Meteor](http://www.meteor.com/) application adds `Job` and `JobsWorker` classes\ninto the global scope.\n\nServer side only (with `JobsWorker` available on the client side as well).\n\nInstallation\n------------\n\n```\nmeteor add peerlibrary:classy-job\n```\n\nJobs\n----\n\nThe basic use is to extend `Job` class and implement the `run` method:\n\n```javascript\nclass ExampleJob extends Job {\n  run() {\n    this.logInfo(\"Hello world from: \" + this.data.name);\n  }\n}\n\nExampleJob.register();\n```\n\n`run` is expected to be blocking and when it returns the job is seen as successfully completed. The return value\nis stored in the job's result. If `run` throws an exception, the job is marked as failed and exception is logged.\n\nThen, when you want to put a new instance of the job into the queue, run:\n\n```javascript\nnew ExampleJob({name: \"Foo\"}).enqueue({skipIfExisting: true});\n```\n\nClass constructor receives data which is then available to the job when it is run (data is stored\nin the database and retrieved on a worker, so it should be EJSON-serializable).\n\n`enqueue` accepts the following options:\n* `skipIfExisting`, if true, the job will not be enqueued if a not-completed job already exists\n* `skipIncludingCompleted`, if true, together with `skipIfExisting`, the job will not be enqueued if a job already exists, even if completed \n* `depends`, if set it is passed to [job collection's `depends`](https://github.com/vsivsi/meteor-job-collection#jobdependsdependencies---anywhere)\n* `priority`, if set it is passed to [job collection's `priority`](https://github.com/vsivsi/meteor-job-collection#jobprioritypriority---anywhere)\n* `retry`, if set it is passed to [job collection's `retry`](https://github.com/vsivsi/meteor-job-collection#jobretryoptions---anywhere)\n* `repeat`, if set it is passed to [job collection's `repeat`](https://github.com/vsivsi/meteor-job-collection#jobrepeatoptions---anywhere)\n* `delay`, if set it is passed to [job collection's `delay`](https://github.com/vsivsi/meteor-job-collection#jobdelaymilliseconds---anywhere)\n* `after`, if set it is passed to [job collection's `after`](https://github.com/vsivsi/meteor-job-collection#jobaftertime---anywhere)\n* `save`, if set it is passed to [job collection's `save`](https://github.com/vsivsi/meteor-job-collection#jobsaveoptions-callback---anywhere)\n\nWhen using `skipIfExisting` there is a slight race-condition possible. In the worst case there will be\nsome duplicate work done. This should not be a problem because jobs ought to be idempotent anyway.\n\nInitialization\n--------------\n\nCall `JobsWorker.initialize()` in your app on both client and server to initialize the worker environment and\n`JobsWorker.collection` collection.\n\nPossible options for `JobsWorker.initialize` with defaults:\n\n```javascript\nJobsWorker.initialize({\n  collectionName: 'JobQueue',\n  workerInstances: parseInt(process.env.WORKER_INSTANCES || '1'),\n  stalledJobCheckInterval: 60 * 1000, // ms\n  promoteInterval: 15 * 1000 // ms\n});\n```\n\nYou can use `WORKER_INSTANCES` environment variable or `workerInstances` option to control how many workers are enabled\nacross all Meteor instances for your app. If set to `0` the current Meteor instance will not run a worker.\n\nCall `JobsWorker.start` on the server to start the worker:\n\n```javascript\nMeteor.startup(function () {\n  JobsWorker.start()\n});\n```\n\n`JobsWorker.start` call will not do anything if `workerInstances` is `0`. Alternatively, you can simply do not call\n`JobsWorker.start`.\n\nStarting is randomly delayed a bit to distribute the behavior of workers equally inside configured intervals.\n\nJobs are executed serially inside a given worker, one by one.\n\nWorking with jobs\n-----------------\n\nJob classes will be instantiated automatically every time they are ready and their `run`\nmethod will be called.\nInside your `run` method you can call other methods, for example `log` or `progress` to report\non job's progress.\n\nYou can use `Job.find(query, fields)` and `Job.findOne(query, fields)` to get instances of jobs from the database.\nResulting objects will be proper instances of your job classes of the correct type for each result object.\nIf you want only types of a particular class you can limit the query yourself:\n\n```javascript\nJob.find({\n  type: ExampleJob.type()\n});\n```\n\nIf you need access to any other functionality of job collection not available directly through\nexisting methods, you can call `getQueueJob` to get underlying job collection's job.\nWe call job collection's jobs *queue jobs*.\n\nSo, for example, to [cancel](https://github.com/vsivsi/meteor-job-collection#jobcanceloptions-callback---anywhere) a\njob, you can do:\n\n```javascript\nJob.findOne({\n  'data.argument': 'foobar'\n}).getQueueJob().cancel();\n```\n\nYou can use `JobsWorker.collection` to access underlying [job collection](https://github.com/vsivsi/meteor-job-collection).\nTo convert its jobs (queue jobs) to an instance of a class-based job you can use `Job.fromQueueJob(job)`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-classy-job","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeerlibrary%2Fmeteor-classy-job","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerlibrary%2Fmeteor-classy-job/lists"}