{"id":13406632,"url":"https://github.com/miaowing/nest-schedule","last_synced_at":"2025-12-24T19:12:00.834Z","repository":{"id":32626190,"uuid":"138335708","full_name":"miaowing/nest-schedule","owner":"miaowing","description":"A cron-like and not-cron-like job distributed scheduler for Nest.js by decorators.","archived":false,"fork":false,"pushed_at":"2023-01-07T04:54:51.000Z","size":450,"stargazers_count":438,"open_issues_count":37,"forks_count":33,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-10-16T15:47:14.933Z","etag":null,"topics":["cron","microservice","nest","nest-schedule","nestcloud","nestjs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/miaowing.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":"2018-06-22T18:29:13.000Z","updated_at":"2025-10-03T05:24:19.000Z","dependencies_parsed_at":"2023-01-14T21:45:55.929Z","dependency_job_id":null,"html_url":"https://github.com/miaowing/nest-schedule","commit_stats":null,"previous_names":["miaowing/schedule","nest-cloud/schedule"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/miaowing/nest-schedule","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaowing%2Fnest-schedule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaowing%2Fnest-schedule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaowing%2Fnest-schedule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaowing%2Fnest-schedule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miaowing","download_url":"https://codeload.github.com/miaowing/nest-schedule/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaowing%2Fnest-schedule/sbom","scorecard":{"id":640506,"data":{"date":"2025-08-11","repo":{"name":"github.com/miaowing/nest-schedule","commit":"34464787160a8652f34d8d7f087e7d296a029987"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":2,"reason":"Found 3/13 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 20 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"48 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-cj7v-w2c7-cp7c","Warn: Project is vulnerable to: GHSA-4jpv-8r57-pv7j","Warn: Project is vulnerable to: GHSA-42xw-2xvc-qx8m","Warn: Project is vulnerable to: GHSA-4w2v-q235-vp99","Warn: Project is vulnerable to: GHSA-cph5-m8f7-6c5x","Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx","Warn: Project is vulnerable to: GHSA-jr5f-v2jv-69x6","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-wm7h-9275-46v2","Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4","Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g","Warn: Project is vulnerable to: GHSA-56x4-j7p9-fcf9","Warn: Project is vulnerable to: GHSA-v78c-4p63-2j6c","Warn: Project is vulnerable to: GHSA-44fp-w29j-9vj5","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp","Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T10:34:18.361Z","repository_id":32626190,"created_at":"2025-08-21T10:34:18.361Z","updated_at":"2025-08-21T10:34:18.361Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28006425,"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","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cron","microservice","nest","nest-schedule","nestcloud","nestjs"],"created_at":"2024-07-30T19:02:35.218Z","updated_at":"2025-12-24T19:12:00.818Z","avatar_url":"https://github.com/miaowing.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Components \u0026 Libraries","资源"],"sub_categories":["组件和库"],"readme":"\n[travis-image]: https://api.travis-ci.org/nest-cloud/nestcloud.svg?branch=master\n[travis-url]: https://travis-ci.org/nest-cloud/nestcloud\n[linux-image]: https://img.shields.io/travis/nest-cloud/nestcloud/master.svg?label=linux\n[linux-url]: https://travis-ci.org/nest-cloud/nestcloud\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"320\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# Nest Schedule\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.npmjs.com/~nest-schedule\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/nest-schedule.svg\" alt=\"NPM Version\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/~nest-schedule\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/nest-schedule.svg\" alt=\"Package License\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/~nest-schedule\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/nest-schedule.svg\" alt=\"NPM Downloads\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n\nThis is a [Nest](https://github.com/nestjs/nest) module for using decorator schedule jobs.\n\n\n## Installation\n\n```bash\n$ npm i --save nest-schedule\n```\n\n\n## Usage\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ScheduleModule } from 'nest-schedule';\n\n@Module({\n  imports: [\n    ScheduleModule.register(),\n  ]\n})\nexport class AppModule {\n}\n```\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { Cron, Interval, Timeout, NestSchedule } from 'nest-schedule';\n\n@Injectable() // Only support SINGLETON scope\nexport class ScheduleService extends NestSchedule {    \n  @Cron('0 0 2 * *', {\n    startTime: new Date(), \n    endTime: new Date(new Date().getTime() + 24 * 60 * 60 * 1000),\n  })\n  async cronJob() {\n    console.log('executing cron job');\n  }\n  \n  @Timeout(5000)\n  onceJob() {\n    console.log('executing once job');\n  }\n  \n  @Interval(2000)\n  intervalJob() {\n    console.log('executing interval job');\n    \n    // if you want to cancel the job, you should return true;\n    return true;\n  }\n}\n```\n\n### Dynamic Schedule Job\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectSchedule, Schedule } from 'nest-schedule';\n\n@Injectable()\nexport class ScheduleService {    \n  constructor(\n    @InjectSchedule() private readonly schedule: Schedule,\n  ) {\n  }\n  \n  createJob() {\n    // schedule a 2s interval job\n    this.schedule.scheduleIntervalJob('my-job', 2000, () =\u003e {\n      console.log('executing interval job');\n    });\n  }\n  \n  cancelJob() {\n    this.schedule.cancelJob('my-job');\n  }\n}\n```\n\n### Distributed Support\n\n#### 1. Extend NestDistributedSchedule class\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { Cron, NestDistributedSchedule } from 'nest-schedule';\n\n@Injectable()\nexport class ScheduleService extends NestDistributedSchedule {  \n  constructor() {\n    super();\n  }\n  \n  async tryLock(method: string) {\n    if (lockFail) {\n      return false;\n    }\n    \n    return () =\u003e {\n      // Release here.\n    }\n  }\n  \n  @Cron('0 0 4 * *')\n  async cronJob() {\n    console.log('executing cron job');\n  }\n}\n```\n\n#### 2. Use UseLocker decorator\n\n```typescript\nimport { ILocker, IScheduleConfig, InjectSchedule, Schedule } from 'nest-schedule';\nimport { Injectable } from '@nestjs/common';\n\n// If use NestCloud, it supports dependency injection.\n@Injectable()\nexport class MyLocker implements ILocker {\n  private key: string;\n  private config: IScheduleConfig;\n\n  constructor(\n    @InjectSchedule() private readonly schedule: Schedule,\n  ) {\n  }\n\n  init(key: string, config: IScheduleConfig): void {\n    this.key = key;\n    this.config = config;\n    console.log('init my locker: ', key, config);\n  }\n\n  release(): any {\n    console.log('release my locker');\n  }\n\n  tryLock(): Promise\u003cboolean\u003e | boolean {\n    console.log('apply my locker');\n    return true;\n  }\n}\n```\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { Cron, NestSchedule, UseLocker } from 'nest-schedule';\nimport { MyLocker } from './my.locker';\n\n@Injectable()\nexport class ScheduleService extends NestSchedule {  \n  @Cron('0 0 4 * *')\n  @UseLocker(MyLocker)\n  async cronJob() {\n    console.log('executing cron job');\n  }\n}\n```\n\n\n## API\n\n### class ScheduleModule\n\n#### static register\\(config: IGlobalConfig\\): DynamicModule\n\nRegister schedule module.\n\n| field | type | required | description |\n| --- | --- | --- | --- |\n| config.enable | boolean | false | default is true, when false, the job will not execute |\n| config.maxRetry | number | false |  the max retry count, default is -1 not retry |\n| config.retryInterval | number | false | the retry interval, default is 5000 |\n| config.waiting | boolean | false | the scheduler will not schedule job when this job is running, if waiting is true |\n\n### class Schedule\n\n#### scheduleCronJob(key: string, cron: string, callback: JobCallback, config?: ICronJobConfig)\n\nSchedule a cron job.\n\n| field | type | required | description |\n| --- | --- | --- | --- |\n| key | string | true | The unique job key |\n| cron | string | true | The cron expression |\n| callback | () =\u003e Promise\u0026lt;boolean\u0026gt; | boolean | If return true in callback function, the schedule will cancel this job immediately |\n| config.startTime | Date | false | The start time of this job |\n| config.endTime | Date | false | The end time of this job |\n| config.enable | boolean | false | default is true, when false, the job will not execute |\n| config.maxRetry | number | false |  the max retry count, default is -1 not retry |\n| config.retryInterval | number | false | the retry interval, default is 5000 |\n| config.waiting | boolean | false | the scheduler will not schedule job when this job is running, if waiting is true |\n| config.immediate | boolean | false | running job immediately |\n\n#### scheduleIntervalJob(key: string, interval: number, callback: JobCallback, config?: IJobConfig)\n\nSchedule a interval job.\n\n| field | type | required | description |\n| --- | --- | --- | --- |\n| key | string | true | The unique job key |\n| interval | number | true | milliseconds |\n| callback | () =\u003e Promise\u0026lt;boolean\u0026gt; | boolean | If return true in callback function, the schedule will cancel this job immediately |\n| config.enable | boolean | false | default is true, when false, the job will not execute |\n| config.maxRetry | number | false |  the max retry count, default is -1 not retry |\n| config.retryInterval | number | false | the retry interval, default is 5000 |\n| config.waiting | boolean | false | the scheduler will not schedule job when this job is running, if waiting is true |\n| config.immediate | boolean | false | running job immediately |\n\n#### scheduleTimeoutJob(key: string, timeout: number, callback: JobCallback, config?: IJobConfig)\n\nSchedule a timeout job.\n\n| field | type | required | description |\n| --- | --- | --- | --- |\n| key | string | true | The unique job key |\n| timeout | number | true | milliseconds |\n| callback | () =\u003e Promise\u0026lt;boolean\u0026gt; | boolean | If return true in callback function, the schedule will cancel this job immediately |\n| config.enable | boolean | false | default is true, when false, the job will not execute |\n| config.maxRetry | number | false |  the max retry count, default is -1 not retry |\n| config.retryInterval | number | false | the retry interval, default is 5000 |\n| config.immediate | boolean | false | running job immediately |\n\n#### cancelJob(key: string)\n\nCancel job.\n\n\n## Decorators\n\n### Cron(expression: string, config?: ICronJobConfig): MethodDecorator\n\nSchedule a cron job.\n\n| field | type | required | description |\n| --- | --- | --- | --- |\n| expression | string | true | the cron expression |\n| config.key | string | false | The unique job key |\n| config.startTime | Date | false | the job's start time |\n| config.endTime | Date | false | the job's end time |\n| config.enable | boolean | false | default is true, when false, the job will not execute |\n| config.maxRetry | number | false |  the max retry count, default is -1 not retry |\n| config.retryInterval | number | false | the retry interval, default is 5000 |\n| config.waiting | boolean | false | the scheduler will not schedule job when this job is running, if waiting is true |\n| config.immediate | boolean | false | running job immediately |\n\n### Interval(milliseconds: number, config?: IJobConfig): MethodDecorator\n\nSchedule a interval job.\n\n| field | type | required | description |\n| --- | --- | --- | --- |\n| milliseconds | number | true | milliseconds |\n| config.key | string | false | The unique job key |\n| config.enable | boolean | false | default is true, when false, the job will not execute |\n| config.maxRetry | number | false |  the max retry count, default is -1 not retry |\n| config.retryInterval | number | false | the retry interval, default is 5000 |\n| config.waiting | boolean | false | the scheduler will not schedule job when this job is running, if waiting is true |\n| config.immediate | boolean | false | running job immediately |\n\n### Timeout(milliseconds: number, config?: IJobConfig): MethodDecorator\n\nSchedule a timeout job.\n\n| field | type | required | description |\n| --- | --- | --- | --- |\n| milliseconds | number | true | milliseconds |\n| config.key | string | false | The unique job key |\n| config.enable | boolean | false | default is true, when false, the job will not execute |\n| config.maxRetry | number | false |  the max retry count, default is -1 not retry |\n| config.retryInterval | number | false | the retry interval, default is 5000 |\n| config.immediate | boolean | false | running job immediately |\n\n### InjectSchedule(): PropertyDecorator\n\nInject Schedule instance\n\n### UseLocker(locker: ILocker | Function): MethodDecorator\n\nMake your job support distribution.\n \nIf you use [NestCloud](https://github.com/nest-cloud/nestcloud), the Locker will support dependency injection, or not use injection please.\n\n\n## Stay in touch\n\n- Author - [miaowing](https://github.com/miaowing)\n\n## License\n\n- NestSchedule is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiaowing%2Fnest-schedule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiaowing%2Fnest-schedule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiaowing%2Fnest-schedule/lists"}