new Task()
- Source:
- Tutorials:
Properties:
| Name | Type | Description |
|---|---|---|
name |
string | The name of the Task. |
description |
string | The description of the Task (default this.name). |
frequency |
Number | How often to run this Task, in ms. 0 is non-recurring. (default: 0). |
middleware |
Array | The Middleware specific to this Task (default: []). Middleware is descibed by the string names of the middleware. |
queue |
string | The default queue to run this Task on (default: 'default'). |
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.
Example
'use strict'
const ActionHero = require('actionhero')
module.exports = class SayHello extends ActionHero.Task {
constructor () {
super()
this.name = 'sayHello'
this.description = 'I say Hello every minute'
this.frequency = (60 * 1000)
}
async run (data) {
ActionHero.api.log('Hello!')
}
}
Methods
(async, static) run(data)
- Source:
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.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object | The data about this instance of the task, specifically params. |