Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

const { Task, api, log } = require('actionhero')
module.exports = 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!')
 }
}

Hierarchy

Index

Constructors

constructor

Properties

description

description: string

The description of the Task (default this.name)

frequency

frequency: number

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

middleware

middleware: Array<string>

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

name

name: string

The name of the Task

pluginOptions

pluginOptions: Array<string>

Options for the node-resque plugins.

plugins

plugins: Array<string>

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

queue

queue: string

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

reEnqueuePeriodicTaskIfException

reEnqueuePeriodicTaskIfException: boolean

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

Methods

Private defaults

  • defaults(): object
  • Returns object

    • description: string
    • frequency: number
    • middleware: undefined[]
    • name: null
    • pluginOptions: undefined[]
    • plugins: undefined[]
    • queue: string
    • reEnqueuePeriodicTaskIfException: boolean

Abstract run

  • run(data: TaskData, worker: any): Promise<any>
  • The main "do something" method for this task. It can be async. Anything returned from this metod 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.

    Inputs:

    • 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.

    Parameters

    Returns Promise<any>

validate

  • validate(): void

Generated using TypeDoc