A general and powerful tool to run tasks written in nodejs.
yarn add @optask/tasker
Inside your project create a new task:
import { BaseTask, EqualsCondition } from '@optask/tasker';
export class MigrateTask extends BaseTask {
constructor() {
super({
name: 'Migrate',
condition: new EqualsCondition('version', '1.2.0'),
});
}
override async run(args: string[]) {
const db = someDBConnection(args);
await db.migrate();
}
}
Then run it with a scheduler:
import { TaskScheduler } from '@optask/tasker';
import { MigrateTask } from 'MigrateTask';
const scheduler = new TaskScheduler();
// Add the tasks to run to the task scheduler
scheduler.registerTask(new MigrateTask());
// Tell the scheduler about the conditions it is running under
scheduler.addCondition(`version`, process.env.VERSION);
// Finally run the tasks with the scheduler
await scheduler.run();
There are several packages in this repo depending on your use case, but all extend from the base package @optask/tasker.
- Tasker: @optask/tasker. Base package.
- NestJS: @optask/nestjs. A wrapper for nestjs apps.
- S3 Storage: @optask/storage-s3. A store implementation using s3.
- Redis Storage: @optask/storage-redis. A store implementation using redis.
There is more information in the readmes for those packages.