Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xstoudi/adonis-scheduler
Unopinionated scheduler for Adonis
https://github.com/xstoudi/adonis-scheduler
adonis adonis5 adonisjs adonisjs5 cron schedule scheduler task
Last synced: about 1 month ago
JSON representation
Unopinionated scheduler for Adonis
- Host: GitHub
- URL: https://github.com/xstoudi/adonis-scheduler
- Owner: Xstoudi
- License: mit
- Created: 2023-01-07T18:47:27.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-11T15:20:01.000Z (over 1 year ago)
- Last Synced: 2024-10-08T17:41:00.799Z (about 1 month ago)
- Topics: adonis, adonis5, adonisjs, adonisjs5, cron, schedule, scheduler, task
- Language: TypeScript
- Homepage:
- Size: 745 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Installation
This package is available in the npm registry.
```
npm i @stouder-io/adonis-scheduler
```Next, configure the package by running the following command.
```
node ace configure @stouder-io/adonis-scheduler
```## Usage
The scheduler will start with your Adonis server, but no task is loaded.To create a task, run the following command.
```
node ace make:task MyFirstTask
```This will create the following file under `app/Tasks` directory:
```ts
import { TaskContract } from '@ioc:StouderIO/Scheduler'export default class MyFirstTask implements TaskContract {
public readonly name: string = '{{ name }}'
public readonly cron: string = '* * * * *'public async run(): Promise {
}
}
```The `run` method is called when the scheduler run the task according to the cron expression you configure in the `cron` field. `name` is just for internal use, but it must be unique.
Please note that running CPU-intensive operations in the task has the potential to block your full web application as Node.js is single-threaded.
If you need to run high-intensive CPU task, you could run an Ace command using `execa`, for example:
```ts
import { TaskContract } from '@ioc:StouderIO/Scheduler'
import execa from 'execa'export default class MyFirstTask implements TaskContract {
public readonly name: string = 'test-task'
public readonly cron: string = '* * * * *'public async run(): Promise {
// will execute `node ace intensive` every minute
execa.node('ace', ['intensive'], { stdio: 'inherit' })
}
}
```Also, if you run multiple instances of your Adonis application, the tasks will be ran on each instance.