Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Task

Hierarchy

  • Task

Index

Constructors

constructor

  • Cron task handled by Modules

    Parameters

    • task: TaskOptions

      Description of the task

      const task = new Task({
              schedule: '* * 10 * * *',
              action: () => performActionMethod()
      })
      
      task.start()
      

    Returns Task

Properties

Protected Readonly _action

_action: TaskAction

Action to run on job triggered

Protected Readonly _id

_id: number

Task ID

Protected _job

_job: CronJob

Inter job that will trigger the action (actual task)

Protected _lastCall

_lastCall: Moment

Last task run

Protected Readonly _log

_log: Debugger

Task logger

Protected Readonly _origin

_origin: Module

Task origin object

Static Private _counter

_counter: number = 0

ID counter

Static Private _pool

_pool: Task[] = []

Task pool

Accessors

id

  • get id(): number

lastCall

  • get lastCall(): Moment

nextCall

  • get nextCall(): Moment

origin

running

  • get running(): boolean

Static count

  • get count(): number

Static runningTasks

  • get runningTasks(): Task[]

Static stoppedTasks

  • get stoppedTasks(): Task[]

Static tasks

  • get tasks(): Task[]

Methods

Private run

  • run(): Promise<any>
  • Run the task action

    Returns Promise<any>

    The return of the task action

start

  • start(): void
  • Enable the task

    const task = new Task({ ... })
    
    task.start()
    

    Returns void

stop

  • stop(): void
  • Disable the task

    const task = new Task({ ... })
    
    task.start()
    
    ...
    
    task.stop()
    

    Returns void

Static from

  • Get all tasks from the same origin

    Parameters

    • origin: string | Module

      Origin of the tasks, null or 'Orphan' for orphan tasks

    Returns Task[]

    The list of the tasks

    const tasks = Task.from(MyModule)
    
    console.log(`MyModule is running ${tasks.length} task(s)`)
    

Generated using TypeDoc