Socket
Book a DemoInstallSign in
Socket

@alterior/tasks

Package Overview
Dependencies
Maintainers
0
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alterior/tasks

Flexible background task system

latest
Source
npmnpm
Version
3.11.1
Version published
Maintainers
0
Created
Source

@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 ]);

Keywords

background

FAQs

Package last updated on 15 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts