🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@stouder-io/adonis-scheduler

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stouder-io/adonis-scheduler

Unopinionated scheduler for Adonis

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

@stouder-io/adonis-scheduler

Unopinionated scheduler for Adonis

npm

Installation

This package is available in the npm registry.

npm i @stouder-io/adonis-scheduler

Next, configure the package by running the following command.

node ace configure @stouder-io/adonis-scheduler

Usage

The scheduler will start with your Adonis server, but no task is loaded.

To create a task, run the following command.

node ace make:task MyFirstTask

This will create the following file under app/Tasks directory:

import { TaskContract } from '@ioc:StouderIO/Scheduler'

export default class MyFirstTask implements TaskContract {
  public readonly name: string = '{{ name }}'
  public readonly cron: string = '* * * * *'

  public async run(): Promise<void> {
    
  }
}

The run method is called when the scheduler run the task according to the cron expression you configure in the cron field. name is just for internal use, but it must be unique.

Please note that running CPU-intensive operations in the task has the potential to block your full web application as Node.js is single-threaded.

If you need to run high-intensive CPU task, you could run an Ace command using execa, for example:

import { TaskContract } from '@ioc:StouderIO/Scheduler'
import execa from 'execa'

export default class MyFirstTask implements TaskContract {
  public readonly name: string = 'test-task'
  public readonly cron: string = '* * * * *'

  public async run(): Promise<void> {
    // will execute `node ace intensive` every minute
    execa.node('ace', ['intensive'], { stdio: 'inherit' })
  }
}

Also, if you run multiple instances of your Adonis application, the tasks will be ran on each instance.

Keywords

adonis

FAQs

Package last updated on 10 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts