{"id":19633008,"url":"https://github.com/kabbouchi/adonisjs-scheduler","last_synced_at":"2025-04-05T14:03:26.705Z","repository":{"id":62907475,"uuid":"563529306","full_name":"KABBOUCHI/adonisjs-scheduler","owner":"KABBOUCHI","description":"Task scheduler for AdonisJS","archived":false,"fork":false,"pushed_at":"2025-03-22T13:24:06.000Z","size":833,"stargazers_count":64,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T13:05:27.382Z","etag":null,"topics":["adonisjs","cron","cronjob","scheduler"],"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/KABBOUCHI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2022-11-08T20:00:27.000Z","updated_at":"2025-03-27T02:53:18.000Z","dependencies_parsed_at":"2024-12-17T03:11:15.790Z","dependency_job_id":"f3081b91-03c6-4545-8995-31cf5719beb1","html_url":"https://github.com/KABBOUCHI/adonisjs-scheduler","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"c3afe39d8252b972583bb306100a777cdfcde2d1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fadonisjs-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fadonisjs-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fadonisjs-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fadonisjs-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KABBOUCHI","download_url":"https://codeload.github.com/KABBOUCHI/adonisjs-scheduler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345850,"owners_count":20924102,"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":["adonisjs","cron","cronjob","scheduler"],"created_at":"2024-11-11T12:15:59.224Z","updated_at":"2025-04-05T14:03:26.683Z","avatar_url":"https://github.com/KABBOUCHI.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e\u003cb\u003eAdonisJS Scheduler\u003c/b\u003e\u003c/h1\u003e\n\n  \u003cp\u003eTask scheduler for AdonisJS v6\u003c/p\u003e\n\n  \u003cp\u003e\n    \u003ca href=\"https://npmjs.org/package/adonisjs-scheduler\" target=\"_blank\"\u003e\n      \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/adonisjs-scheduler.svg?style=for-the-badge\u0026logo=npm\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/KABBOUCHI/adonisjs-scheduler/blob/master/LICENSE.md\" target=\"_blank\"\u003e\n      \u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/npm/l/adonisjs-scheduler?color=blueviolet\u0026style=for-the-badge\" /\u003e\n    \u003c/a\u003e\n    \u003cimg alt=\"Typescript\" src=\"https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge\u0026logo=typescript\" /\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/KABBOUCHI/adonisjs-scheduler/master/example.png\" alt=\"Scheduler code example\"\u003e\n\u003c/p\u003e\n\n\u003caside class=\"notice\"\u003e\n  \u003ca href=\"https://github.com/KABBOUCHI/adonisjs-scheduler/tree/0.x\"\u003eFor AdonisJS v5 use 0.x branch\u003c/a\u003e\n\u003c/aside\u003e\n\n## Installation\n\nInstall the package from npm using the following command:\n\n```bash\nnode ace add adonisjs-scheduler\n```\n\n## Running The Scheduler\n\n```sh\nnode ace scheduler:run\n# or\nnode ace scheduler:work\n\n# automatically restart the scheduler when files are modified during development mode\nnode ace scheduler:run --watch\n```\n\n## Defining Schedules\n\n```ts\n// start/scheduler.ts\n\nimport scheduler from 'adonisjs-scheduler/services/main'\n\nimport PurgeUsers from '../commands/purge_users'\n\nscheduler.command('inspire').everyFiveSeconds()\nscheduler.command(PurgeUsers, ['30 days']).everyFiveSeconds().withoutOverlapping()\n\nscheduler.withoutOverlapping(\n  () =\u003e {\n    scheduler.command('inspire').everySecond()\n    scheduler.command(PurgeUsers, ['30 days']).everyFiveSeconds()\n  },\n  { expiresAt: 30_000 }\n)\n\nscheduler\n  .call(() =\u003e {\n    console.log('Pruge DB!')\n  })\n  .weekly()\n```\n\nor define schedule directly on command\n\n```ts\nimport { BaseCommand, args } from '@adonisjs/core/ace'\nimport { schedule } from 'adonisjs-scheduler'\n\n@schedule(\"* * * * *\", [\"30 days\"])\n@schedule((s) =\u003e s.everyFiveSeconds().immediate(), [\"7 days\"])\n@schedule((s) =\u003e s.everyMinute(), [\"42 days\"])\nexport default class PurgeUsers extends BaseCommand {\n  static commandName = 'purge:users'\n  static description = ''\n\n  static options: CommandOptions = {}\n\n  @args.string()\n  declare olderThan: string\n\n  async run() {\n    //\n  }\n}\n```\n\n\n## Schedule Frequency Options\n\n| Method                           | Description                                             |\n| -------------------------------- | ------------------------------------------------------- |\n| `.cron('* * * * *');`            | Run the task on a custom cron schedule                  |\n| `.everyMinute();`                | Run the task every minute                               |\n| `.everyTwoMinutes();`            | Run the task every two minutes                          |\n| `.everyThreeMinutes();`          | Run the task every three minutes                        |\n| `.everyFourMinutes();`           | Run the task every four minutes                         |\n| `.everyFiveMinutes();`           | Run the task every five minutes                         |\n| `.everyTenMinutes();`            | Run the task every ten minutes                          |\n| `.everyFifteenMinutes();`        | Run the task every fifteen minutes                      |\n| `.everyThirtyMinutes();`         | Run the task every thirty minutes                       |\n| `.hourly();`                     | Run the task every hour                                 |\n| `.hourlyAt(17);`                 | Run the task every hour at 17 minutes past the hour.    |\n| `.everyTwoHours();`              | Run the task every two hours                            |\n| `.everyThreeHours();`            | Run the task every three hours                          |\n| `.everyFourHours();`             | Run the task every four hours                           |\n| `.everyFiveHours();`             | Run the task every five hours                           |\n| `.everySixHours();`              | Run the task every six hours                            |\n| `.daily();`                      | Run the task every day at midnight                      |\n| `.dailyAt('13:00');`             | Run the task every day at 13:00.                        |\n| `.twiceDaily(1, 13);`            | Run the task daily at 1:00 \u0026 13:00.                     |\n| `.twiceDailyAt(1, 13, 15);`      | Run the task daily at 1:15 \u0026 13:15.                     |\n| `.weekly();`                     | Run the task every Sunday at 00:00                      |\n| `.weeklyOn(1, '8:00');`          | Run the task every week on Monday at 8:00.              |\n| `.monthly();`                    | Run the task on the first day of every month at 00:00   |\n| `.monthlyOn(4, '15:00');`        | Run the task every month on the 4th at 15:00.           |\n| `.twiceMonthly(1, 16, '13:00');` | Run the task monthly on the 1st and 16th at 13:00.      |\n| `.lastDayOfMonth('15:00');`      | Run the task on the last day of the month at 15:00.     |\n| `.quarterly();`                  | Run the task on the first day of every quarter at 00:00.|\n| `.quarterlyOn(4, '14:00');`      | Run the task every quarter on the 4th at 14:00.         |\n| `.yearly();`                     | Run the task on the first day of every year at 00:00.   |\n| `.yearlyOn(6, 1, '17:00');`      | Run the task every year on June 1st at 17:00.           |\n| `.timezone('America/New_York');` | Set the timezone for the task.                          |\n| `.immediate();`                  | Run the task on startup                                 |\n| `.withoutOverlapping();`         | Run the task without overlapping                        |\n\n\n## Alternative Ways to Run the Scheduler\n\nBesides using `node ace scheduler:run`, you can also manually initialize and control the scheduler worker in your code:\n\n```ts\nimport { Worker } from 'adonisjs-scheduler'\nimport app from '@adonisjs/core/services/app'\n\nconst worker = new Worker(app)\n\napp.terminating(async () =\u003e {\n  await worker.stop()\n})\n\nawait worker.start()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabbouchi%2Fadonisjs-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkabbouchi%2Fadonisjs-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabbouchi%2Fadonisjs-scheduler/lists"}