{"id":23764470,"url":"https://github.com/chaqchase/cronbake","last_synced_at":"2025-09-05T08:33:34.675Z","repository":{"id":270165289,"uuid":"786508703","full_name":"chaqchase/cronbake","owner":"chaqchase","description":"Cronbake - A Powerful and Flexible Cron Job Manager powered by Bun","archived":false,"fork":false,"pushed_at":"2024-04-18T09:34:50.000Z","size":79,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-29T00:24:37.710Z","etag":null,"topics":["bun","cron","cronjob"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cronbake","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/chaqchase.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-04-14T17:18:11.000Z","updated_at":"2024-11-15T14:33:27.000Z","dependencies_parsed_at":"2024-12-29T00:24:46.063Z","dependency_job_id":"4e0fd211-a9c4-4e27-a913-79d36d08794d","html_url":"https://github.com/chaqchase/cronbake","commit_stats":null,"previous_names":["chaqchase/cronbake"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fcronbake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fcronbake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fcronbake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaqchase%2Fcronbake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaqchase","download_url":"https://codeload.github.com/chaqchase/cronbake/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232032239,"owners_count":18462988,"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":["bun","cron","cronjob"],"created_at":"2024-12-31T22:18:16.749Z","updated_at":"2024-12-31T22:18:18.183Z","avatar_url":"https://github.com/chaqchase.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cronbake - A Powerful and Flexible Cron Job Manager powered by Bun\n\nCronbake is a powerful and flexible cron job manager built with TypeScript powered by Bun. It provides an easy-to-use interface for scheduling and managing cron jobs with a wide range of options and features. Cronbake is designed to be lightweight, efficient, and highly configurable, making it suitable for a variety of use cases.\n\n### Features\n\n#### Expressive Cron Expressions\n\nCronbake supports a wide range of cron expressions, including standard formats, ranges, steps, lists, and presets. You can use the following formats or presets:\n\n- **Wildcards**: `* * * * * *` (second minute hour day month day-of-week)\n- **Ranges**: `1-10 * * * * *`\n- **Steps**: `1-10/2 * * * * *` (can be used with wildcards and ranges)\n- **Lists**: `1,2,3 * * * * *`\n- **Presets**:\n  - `@every_second`\n  - `@every_minute`\n  - `@yearly` or `@annually`\n  - `@monthly`\n  - `@weekly`\n  - `@daily`\n  - `@hourly`\n- **Custom Presets**: (as for now you can only use one presets at a time for each cron job in the format of `@\u003cpreset\u003e_\u003cvalue\u003e` the support for multiple presets will be added in the future)\n  - `@every_\u003cnumber\u003e_\u003cunit\u003e` (where `\u003cunit\u003e` is one of `seconds`, `minutes`, `hours`, `dayOfMonth`, `months`, `dayOfWeek`)\n  - `@at_\u003chour\u003e:\u003cminute\u003e` (where `\u003chour\u003e` is a number between 0 and 23, and `\u003cminute\u003e` is a number between 0 and 59)\n  - `@on_\u003cday\u003e` (where `\u003cday\u003e` is one of `sunday`, `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`)\n  - `@between_\u003chour\u003e_\u003chour\u003e` (where `\u003chour\u003e` is a number between 0 and 23)\n\nThis a simple graph to show how the cron expression works:\n\n```plaintext\n* * * * * * (second minute hour day month day-of-week)\n| | | | | |\n| | | | | +-- day of the week (0 - 6) (Sunday to Saturday)\n| | | | +---- month (1 - 12)\n| | | +------ day of the month (1 - 31)\n| | +-------- hour (0 - 23)\n| +---------- minute (0 - 59)\n+------------ second (0 - 59)\n```\n\n#### Cron Job Management\n\nCronbake provides a simple and intuitive interface for managing cron jobs. You can easily add, remove, start, stop, and destroy cron jobs using the `Baker` class.\n\n#### Real-time Status\n\nCronbake allows you to get the current status, last execution time, next execution time, and remaining time for each cron job. This information can be useful for monitoring and debugging purposes.\n\n#### Callbacks\n\nWith Cronbake, you can execute custom functions when a cron job ticks (runs) or completes. This allows you to perform any necessary actions or side effects related to your cron job.\n\n#### Type-safe\n\nCronbake is built with TypeScript, ensuring type safety and better tooling support. This helps catch errors during development and provides better code navigation and auto-completion.\n\n### Installation\n\nYou can install Cronbake using your preferred package manager:\n\n```bash\n# With Bun\nbun add cronbake\n\n# With npm\nnpm install cronbake\n\n# With yarn\nyarn add cronbake\n\n# With pnpm\npnpm add cronbake\n```\n\n### Usage\n\nTo get started with Cronbake, create a new instance of the `Baker` class and add cron jobs using the `add` method:\n\n```typescript\nimport Baker from 'cronbake';\n\n// Create a new Baker instance\nconst baker = Baker.create();\n\n// Add a cron job that runs daily at midnight\nconst dailyJob = baker.add({\n  name: 'daily-job',\n  cron: '0 0 0 * * *', // Runs daily at midnight\n  callback: () =\u003e {\n    console.log('Daily job executed!');\n  },\n});\n\n// Runs every first 3 minutes for the first 3 hours of every day\nconst everyFirst3MinutesJob = baker.add({\n  name: 'every-first-3-minutes-job',\n  cron: '0 0-3 1,2,3 * * *', // Runs every first 3 minutes for the first 3 hours of every day\n  callback: () =\u003e {\n    console.log('Every first 3 minutes job executed!');\n  },\n});\n\n// using custom presets\nconst everyMinuteJob = baker.add({\n  name: 'every-minute-job',\n  cron: '@every_minute',\n  callback: () =\u003e {\n    console.log('Every minute job executed!');\n  },\n});\n\n// Start all cron jobs\nbaker.bakeAll();\n```\n\nYou can manage cron jobs using the various methods provided by the `Baker` class, such as `remove`, `stop`, `destroy`, `getStatus`, `isRunning`, `lastExecution`, `nextExecution`, `remaining`, and `time`.\n\n| Method | Description |\n| --- | --- |\n| `add(options: CronOptions\u003cT\u003e)` | Adds a new cron job to the baker. |\n| `remove(name: string)` | Removes a cron job from the baker. |\n| `bake(name: string)` | Starts a cron job. |\n| `stop(name: string)` | Stops a cron job. |\n| `destroy(name: string)` | Destroys a cron job. |\n| `getStatus(name: string)` | Returns the status of a cron job. |\n| `isRunning(name: string)` | Checks if a cron job is running. |\n| `lastExecution(name: string)` | Returns the last execution time of a cron job. |\n| `nextExecution(name: string)` | Returns the next execution time of a cron job. |\n| `remaining(name: string)` | Returns the remaining time until the next execution of a cron job. |\n| `time(name: string)` | Returns the current time of a cron job. |\n| `bakeAll()` | Starts all cron jobs. |\n| `stopAll()` | Stops all cron jobs. |\n| `destroyAll()` | Destroys all cron jobs. |\n| `static create(options: IBakerOptions)` | Creates a new instance of `Baker`. |\n\n\n#### Advanced Usage\n\nCronbake also provides a `Cron` class that you can use directly to create and manage individual cron jobs. This can be useful if you need more granular control over cron job instances.\n\n```typescript\nimport { Cron } from 'cronbake';\n\n// Create a new Cron instance\nconst job = Cron.create({\n  name: 'custom-job',\n  cron: '1-10/2 1,2,3 * * * *', // Runs every 2 seconds in the first 3 minutes of every hour\n  callback: () =\u003e {\n    console.log('Custom job executed!');\n  },\n  onTick: () =\u003e {\n    console.log('Job ticked!');\n  },\n  onComplete: () =\u003e {\n    console.log('Job completed!');\n  },\n});\n\n// Start the cron job\njob.start();\n// Stop the cron job\njob.stop();\n// Get the job status\nconst status = job.getStatus();\n// Get the next execution time\nconst nextExecution = job.nextExecution();\n```\n\nCronbake also provides utility functions for parsing cron expressions, getting the next or previous execution times, and validating cron expressions.\n\n```typescript\nimport { Cron } from 'cronbake';\n\n// Parse a cron expression\nconst cronExpression = '0 0 0 * * *';\nconst cronTime = Cron.parse(cronExpression);\n// Get the next execution time for a cron expression\nconst nextExecution = Cron.getNext(cronExpression);\n// Get the previous execution time for a cron expression\nconst previousExecution = Cron.getPrevious(cronExpression);\n// Check if a string is a valid cron expression\nconst isValid = Cron.isValid(cronExpression); // true\n```\n\n| Method | Description |\n| --- | --- |\n| `start()` | Starts the cron job. |\n| `stop()` | Stops the cron job. |\n| `getStatus()` | Returns the current status of the cron job. |\n| `nextExecution()` | Returns the date of the next execution of the cron job. |\n| `static parse(cron: CronExpressionType\u003cT\u003e)` | Parses the specified cron expression and returns a `CronTime` object. |\n| `static getNext(cron: CronExpressionType\u003cT\u003e)` | Gets the next execution time for the specified cron expression. |\n| `static getPrevious(cron: CronExpressionType\u003cT\u003e)` | Gets the previous execution time for the specified cron expression. |\n| `static isValid(cron: CronExpressionType\u003cT\u003e)` | Checks if the specified string is a valid cron expression. |\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.\n\n## License\n\nCronbake is released under the [MIT License](./LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaqchase%2Fcronbake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaqchase%2Fcronbake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaqchase%2Fcronbake/lists"}