@alterior/tasks
TypeScript icon, indicating that this package has built-in type declarations

3.9.0 • Public • Published

@alterior/tasks

Version

Provides a type-safe task queue framework coordinated via Redis.

Getting started

Install the Alterior runtime, the DI library, and the tasks module:

npm install reflect-metadata
npm install @alterior/runtime @alterior/di @alterior/tasks

A minimal example

First, build a task worker:

import { Worker } from '@alterior/tasks';
import { Logger } from '@alterior/logger';

@Task()
export class HelloPrinter extends Worker {
    name = '@myorg/mypackage:Hello';
    
    async sayHello(thing : string) {
        console.log(`Hello ${thing}!`);
    }
}

However, it is more scalable and type-safe to specify a task per class:

@Task()
export class TranscodeToFormatTask extends Worker {
    execute() {
        run(`ffmpeg /storage/${video}.mp4`);
    }
}

@Task()
export class TranscodeTask extends Worker {
    execute() {
        await TranscodeToFormatTask.enqueue({ videoId: 'abcdef', format: '1080p' });
    }
}

@Module({
    tasks: [ MyTask ]
})
export class MyModule {
}

Application.bootstrap(MyModule, [ TaskRunner ]);

Package Sidebar

Install

npm i @alterior/tasks

Weekly Downloads

112

Version

3.9.0

License

MIT

Unpacked Size

451 kB

Total Files

57

Last publish

Collaborators

  • rezonant