• Public
  • Public/Protected
  • All

Class Task

Create a new Actionhero Task. The required properties of an task. These can be defined statically (this.name) or as methods which return a value.

```js import { Task, api, log } from "actionhero"

export default class SayHello extends Task { constructor () { super() this.name = 'sayHello' this.description = 'I say Hello every minute' this.frequency = (60 * 1000) } async run (data, worker) { log('Hello!') } }


  • Task






description: string

The description of the Task (default this.name)

Optional frequency

frequency?: number

How often to run this Task, in ms. 0 is non-recurring. (default: 0)

Optional inputs

inputs?: Inputs

The inputs of the Task (default: {})

Optional middleware

middleware?: string[]

The Middleware specific to this Task (default: []). Middleware is described by the string names of the middleware


name: string

The name of the Task

Optional pluginOptions

pluginOptions?: {}

Options for the node-resque plugins.

Type declaration

  • [key: string]: any

Optional plugins

plugins?: (string | (new (args: [worker: Queue | Worker, func: string, queue: string, job: ParsedJob, args: any[], options: {}]) => Plugin))[]

Plugins from node-resque to use on this task (default: []). Plugins like QueueLock can be applied


queue: string

The default queue to run this Task on (default: 'default')

Optional reEnqueuePeriodicTaskIfException

reEnqueuePeriodicTaskIfException?: boolean

Re-enqueuing a periodic task in the case of an exception. (default: false)


Abstract run

  • run(data: TaskInputs, worker: Worker): Promise<any>
  • The main "do something" method for this task. It can be async. Anything returned from this method will be logged. If error is thrown in this method, it will be logged & caught. Using middleware, you can decide to re-run the task on failure. this is a Task instance itself now.


    • data: The data about this instance of the task, specifically params.
    • worker: Instance of a node-resque worker. You can inspect worker.job and set worker.result explicitly if your Task does not return a value.


    • data: TaskInputs
    • worker: Worker

    Returns Promise<any>

Optional validate

  • validate(): void

Generated using TypeDoc