Skip to content

Function: QueueAction() ​

Call Signature ​

QueueAction<ClassPrototype, Method>(name): MethodDecorator<ClassPrototype, Method, any>

Process the messages of a queue with a controller action: queueEntrypoint delivers each message of the queue to it (its input is the message, validated by the DTO of the action, and this.context a QueueContext). The message is acknowledged when the action returns; after a failure it is delivered again (attempts, backoff), then sent to the dead letter queue <queue>.dead. The value returned is the result of the message (queue.request(), queue.result()), and the input of the output queue. The method may also carry the decorators of the other channels (an HTTP route...).

Type Parameters ​

ClassPrototype ​

ClassPrototype extends Controller

Method ​

Method

Parameters ​

name ​

string

The queue.

Returns ​

MethodDecorator<ClassPrototype, Method, any>

The method decorator.

Example ​

typescript
import {Controller} from 'lakutata/com/entrypoint'
import {QueueAction} from '@lakutata/queue'

class ImageController extends Controller {
    @QueueAction('image.extract', {concurrency: 4, attempts: 5, timeout: '10m', output: 'image.index'})
    public async extract(input: {id: number}): Promise<{id: number, pages: number}> {
        return {id: input.id, pages: 12}
    }

    //The messages which failed
    @QueueAction('image.extract.dead')
    public async failed(input: {jobId: string, error: {message: string}}): Promise<void> {
        console.log(input.jobId, input.error.message)
    }
}

Call Signature ​

QueueAction<ClassPrototype, Method, DTOConstructor>(name, dtoConstructor): MethodDecorator<ClassPrototype, Method, any>

Process the messages of a queue with a controller action: queueEntrypoint delivers each message of the queue to it (its input is the message, validated by the DTO of the action, and this.context a QueueContext). The message is acknowledged when the action returns; after a failure it is delivered again (attempts, backoff), then sent to the dead letter queue <queue>.dead. The value returned is the result of the message (queue.request(), queue.result()), and the input of the output queue. The method may also carry the decorators of the other channels (an HTTP route...).

Type Parameters ​

ClassPrototype ​

ClassPrototype extends Controller

Method ​

Method

DTOConstructor ​

DTOConstructor extends typeof DTO = typeof DTO

Parameters ​

name ​

string

The queue.

dtoConstructor ​

DTOConstructor

Returns ​

MethodDecorator<ClassPrototype, Method, any>

The method decorator.

Example ​

typescript
import {Controller} from 'lakutata/com/entrypoint'
import {QueueAction} from '@lakutata/queue'

class ImageController extends Controller {
    @QueueAction('image.extract', {concurrency: 4, attempts: 5, timeout: '10m', output: 'image.index'})
    public async extract(input: {id: number}): Promise<{id: number, pages: number}> {
        return {id: input.id, pages: 12}
    }

    //The messages which failed
    @QueueAction('image.extract.dead')
    public async failed(input: {jobId: string, error: {message: string}}): Promise<void> {
        console.log(input.jobId, input.error.message)
    }
}

Call Signature ​

QueueAction<ClassPrototype, Method>(name, options): MethodDecorator<ClassPrototype, Method, any>

Process the messages of a queue with a controller action: queueEntrypoint delivers each message of the queue to it (its input is the message, validated by the DTO of the action, and this.context a QueueContext). The message is acknowledged when the action returns; after a failure it is delivered again (attempts, backoff), then sent to the dead letter queue <queue>.dead. The value returned is the result of the message (queue.request(), queue.result()), and the input of the output queue. The method may also carry the decorators of the other channels (an HTTP route...).

Type Parameters ​

ClassPrototype ​

ClassPrototype extends Controller

Method ​

Method

Parameters ​

name ​

string

The queue.

options ​

QueueActionOptions

The options, after a DTO.

Returns ​

MethodDecorator<ClassPrototype, Method, any>

The method decorator.

Example ​

typescript
import {Controller} from 'lakutata/com/entrypoint'
import {QueueAction} from '@lakutata/queue'

class ImageController extends Controller {
    @QueueAction('image.extract', {concurrency: 4, attempts: 5, timeout: '10m', output: 'image.index'})
    public async extract(input: {id: number}): Promise<{id: number, pages: number}> {
        return {id: input.id, pages: 12}
    }

    //The messages which failed
    @QueueAction('image.extract.dead')
    public async failed(input: {jobId: string, error: {message: string}}): Promise<void> {
        console.log(input.jobId, input.error.message)
    }
}

Call Signature ​

QueueAction<ClassPrototype, Method, DTOConstructor>(name, dtoConstructor, options): MethodDecorator<ClassPrototype, Method, any>

Process the messages of a queue with a controller action: queueEntrypoint delivers each message of the queue to it (its input is the message, validated by the DTO of the action, and this.context a QueueContext). The message is acknowledged when the action returns; after a failure it is delivered again (attempts, backoff), then sent to the dead letter queue <queue>.dead. The value returned is the result of the message (queue.request(), queue.result()), and the input of the output queue. The method may also carry the decorators of the other channels (an HTTP route...).

Type Parameters ​

ClassPrototype ​

ClassPrototype extends Controller

Method ​

Method

DTOConstructor ​

DTOConstructor extends typeof DTO = typeof DTO

Parameters ​

name ​

string

The queue.

dtoConstructor ​

DTOConstructor

options ​

QueueActionOptions

The options, after a DTO.

Returns ​

MethodDecorator<ClassPrototype, Method, any>

The method decorator.

Example ​

typescript
import {Controller} from 'lakutata/com/entrypoint'
import {QueueAction} from '@lakutata/queue'

class ImageController extends Controller {
    @QueueAction('image.extract', {concurrency: 4, attempts: 5, timeout: '10m', output: 'image.index'})
    public async extract(input: {id: number}): Promise<{id: number, pages: number}> {
        return {id: input.id, pages: 12}
    }

    //The messages which failed
    @QueueAction('image.extract.dead')
    public async failed(input: {jobId: string, error: {message: string}}): Promise<void> {
        console.log(input.jobId, input.error.message)
    }
}

Released under the MIT License.