{"id":25164392,"url":"https://github.com/cityssm/node-scheduled-task","last_synced_at":"2025-04-03T15:47:31.102Z","repository":{"id":276150280,"uuid":"927305108","full_name":"cityssm/node-scheduled-task","owner":"cityssm","description":"Schedules recurring tasks while managing on-demand executions and limiting simultaneous executions.","archived":false,"fork":false,"pushed_at":"2025-03-10T10:44:32.000Z","size":182,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T22:49:50.722Z","etag":null,"topics":["async","child-process","cron","schedule","task"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@cityssm/scheduled-task","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/cityssm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T18:33:32.000Z","updated_at":"2025-02-20T15:54:55.000Z","dependencies_parsed_at":"2025-02-06T15:52:04.876Z","dependency_job_id":null,"html_url":"https://github.com/cityssm/node-scheduled-task","commit_stats":null,"previous_names":["cityssm/node-scheduled-task"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cityssm%2Fnode-scheduled-task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cityssm%2Fnode-scheduled-task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cityssm%2Fnode-scheduled-task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cityssm%2Fnode-scheduled-task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cityssm","download_url":"https://codeload.github.com/cityssm/node-scheduled-task/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247032945,"owners_count":20872521,"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":["async","child-process","cron","schedule","task"],"created_at":"2025-02-09T04:30:21.632Z","updated_at":"2025-04-03T15:47:31.070Z","avatar_url":"https://github.com/cityssm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scheduled Task\n\n[![NPM Version](https://img.shields.io/npm/v/%40cityssm%2Fscheduled-task)](https://www.npmjs.com/package/@cityssm/scheduled-task)\n[![Maintainability](https://api.codeclimate.com/v1/badges/92e5f4d577e60efb424f/maintainability)](https://codeclimate.com/github/cityssm/node-scheduled-task/maintainability)\n[![codecov](https://codecov.io/gh/cityssm/node-scheduled-task/graph/badge.svg?token=FX2XI74PJQ)](https://codecov.io/gh/cityssm/node-scheduled-task)\n[![DeepSource](https://app.deepsource.com/gh/cityssm/node-scheduled-task.svg/?label=active+issues\u0026show_trend=true\u0026token=iTE12ATmd36uvQAtYrrH7q_B)](https://app.deepsource.com/gh/cityssm/node-scheduled-task/)\n\nSchedules recurring tasks while managing on-demand executions and limiting simultaneous executions.\nHelpful for managing process-heavy tasks running in child processes.\n\n## Installation\n\n```sh\nnpm install @cityssm/scheduled-task\n```\n\n## Usage\n\n### Child Process\n\n```javascript\n// childProcess.js\n\nimport { ScheduledTask } from '@cityssm/scheduled-task'\n\n// Initialize task\nconst task = new ScheduledTask(\n  childProcessTaskName,\n  () =\u003e {\n    /*\n     * Process-heavy code running in the child process.\n     */\n  },\n  {\n    schedule: {\n      second: 0,\n      minute: 0,\n      hour: 0,\n      dayOfWeek: '*',\n      month: '*',\n      year: '*'\n    },\n    minimumIntervalMillis: 10 * 60 * 1000,\n    startTask: true\n  }\n)\n\n// Listen for message to run the task on demand.\nprocess.on('message', (_message) =\u003e {\n  void task.runTask()\n})\n```\n\n#### Options\n\n| Option                  | Description                                                                                                                          | Default  |\n| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -------- |\n| `schedule`              | The frequency the task should run. See [node-schedule](https://www.npmjs.com/package/node-schedule) for acceptable schedule formats. | Midnight |\n| `lastRunMillis`         | The last time the task was executed. Helpful to avoid rerunning a task too soon after a restart.                                     | `0`      |\n| `minimumIntervalMillis` | The minimum amount of time between executions. Helpful if the task can be run on demand.                                             | `0`      |\n| `startTask`             | Whether the task should be started immediately after initialization.                                                                 | `false`  |\n\n### Application\n\n```javascript\n// app.js\n\nimport { fork } from 'node:child_process'\n\nconst childProcess = fork('childProcess.js')\n\nchildProcess.send('Run the task on demand.')\n```\n\n## Real World Example\n\nThis package was made for the City's\n[FASTER Web Helper](https://github.com/cityssm/faster-web-helper) application.\nThe application does a lot of background syncing work in child processes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcityssm%2Fnode-scheduled-task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcityssm%2Fnode-scheduled-task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcityssm%2Fnode-scheduled-task/lists"}