GithubHelp home page GithubHelp logo

nrempel / adonis-scheduler Goto Github PK

View Code? Open in Web Editor NEW
104.0 6.0 33.0 123 KB

This library provides an easy way to schedule recurring tasks for AdonisJS.

License: MIT License

JavaScript 98.91% HTML 1.09%
adonisjs adonis cron task-scheduler

adonis-scheduler's Introduction

Adonis Scheduler Provider

NPM Version Build Status Appveyor Coveralls

This library provides an easy way to schedule recurring tasks for AdonisJS v4.

Use branch adonis-v3 for AdonisJS version 3

Install

npm install --save adonis-scheduler

Configure

Register it in start/app.js:

const providers = [
  ...
  'adonis-scheduler/providers/SchedulerProvider'
]

const aliases = {
  ...
  Scheduler: 'Adonis/Addons/Scheduler'
}

Register the commands:

const aceProviders = [
  ...
  'adonis-scheduler/providers/CommandsProvider'
]

Usage

Starting the scheduler

Starting an instance of the kue listener is easy with the included ace command. Simply run node ace run:scheduler.

The provider looks for jobs in the app/Tasks directory of your AdonisJS project and will automatically register a handler for any tasks that it finds.

Creating your first task

Jobs are easy to create. Run node ace make:task Example. They expose the following properties:

Name Required Type Static Description
schedule true many true The schedule for which the task should run. More docs.
handle true function false A function that is called for this task.

Thanks

Special thanks to the creator(s) of AdonisJS for creating such a great framework.

adonis-scheduler's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

adonis-scheduler's Issues

E_INVALID_SERVICE_PROVIDER: SchedulerProvider must extend base service provider class

I'm trying to run the scheduler using Adonis 4.1 and I'm getting this error.

adonis run:scheduler
RuntimeException: E_INVALID_SERVICE_PROVIDER: SchedulerProvider must extend base service provider class
> More details: https://err.sh/adonisjs/errors/E_INVALID_SERVICE_PROVIDER


1 Function.invoke
  .../node_modules/@adonisjs/fold/node_modules/@adonisjs/generic-exceptions/src/RuntimeException.js:102

2 _.uniq.map
  .../node_modules/@adonisjs/fold/src/Registrar/index.js:107

3 arrayMap
  .../node_modules/lodash/lodash.js:639

4 Function.map
  .../node_modules/lodash/lodash.js:9554

5 interceptor
  .../node_modules/lodash/lodash.js:16997

6 thru
  .../node_modules/lodash/lodash.js:8795

7 anonymous
  .../node_modules/lodash/lodash.js:4368

8 arrayReduce
  .../node_modules/lodash/lodash.js:683

9 baseWrapperValue
  .../node_modules/lodash/lodash.js:4367

10 LazyWrapper.lazyValue [as value]
  .../node_modules/lodash/lodash.js:1859

11 baseWrapperValue
  .../node_modules/lodash/lodash.js:4365

12 LodashWrapper.wrapperValue
  .../node_modules/lodash/lodash.js:9050

13 Registrar._getProvidersInstance
  .../node_modules/@adonisjs/fold/src/Registrar/index.js:111

14 Registrar.providers
  .../node_modules/@adonisjs/fold/src/Registrar/index.js:167

15 Ignitor._registerProviders
  .../node_modules/@adonisjs/ignitor/src/Ignitor/index.js:269

16 Ignitor.fire
  .../node_modules/@adonisjs/ignitor/src/Ignitor/index.js:760

Which version is valid for Adonis 3.2?

I'm using Adonis3.2. I can't seem to make the library start. It's giving me this error when I'm typing ./ace:

SyntaxError: Unexpected identifier
../node_modules/adonis-scheduler/providers/SchedulerProvider.js (../node_modules/adonis-scheduler/providers/SchedulerProvider.js:1:1)

I added everything in the bootstrap/app.js file that was described, but can't make it work. Is 3.0.0 the right version for Adonis 3.2 ?

Run Scheduler with PM2

Hi,
can I run adonisjs-scheduler as service with pm2?
or how to run scheduler on application start

regards,
Arwani

Make handle method to a instance property instead of static

Haven't tried it.

But by looking the example file https://github.com/nrempel/adonis-scheduler/blob/master/examples/app/Tasks/Example.js#L13 and the code, the handle method is a static property on the class, which simply defeats the purpose of creating a class.

I would suggest to make it an instance property and make the task class instance using Ioc.make on this line https://github.com/nrempel/adonis-scheduler/blob/master/src/Scheduler/index.js#L40.

Benefits of Ioc.make

Ioc.make will create an instance of class and will inject any dependencies that class wants. For example.

class RemoveDisabledUsers {

  static get schedule() {
    return '*/1 * * * *';
  }

   static get inject () {
      return ['App/Model/User']
   }

   constructor (User) {
     this.User = User
   }

  * handle () {
     const removeUsers = yield this.User.query().where('status', 'disabled').delete()
   }

}

module.exports = RemoveDisabledUsers;

Above one is more helpful than having the static handle, coz I am able to inject my dependencies automatically.

Also wrap your handle method inside co. Which simply stays in the eco-system of AdonisJs by offering ES2015 generators first approach.

typo in src/Commands/Run.js

Hi,

there is a typo in Run.js:

'user strict';

should be

'use strict';

And in my case handle should only work with co()... But this can be an app specific problem..

Cannot use Adonis Logger provider in Task

It seems that using the Adonis Logger facility is not working inside of tasks.

const Logger = use('Logger')
Logger.info('log') // Does not print to console

@ntvsx193 I noticed that you set up logging so that you can do this.info('log'). What was the motivation for this? Is it possible to have both this.info and Logger.info work?

I haven't had time to dig into it yet but I'll try and take a look this weekend.

AdonisJs CronJobs

How is the "adonis run: scheduler" command registered in the crontab of an Ubuntu operating system?

Package version:
AdonisJs 4.1

Node.js and npm version:
Node js 10.0.1
Npm 3.0

AdonisJs Events wont fired

scheduler running fine
i'm trying to attach to a Event in the end of task
but never catch in bootstrap/event.js

Non-js files are picked up by the run:schedule command

If a non-js file is in the app/Tasks directory scheduler tries to parse it and throws E_INVALID_TASK_SCHEDULE

The obvious solution is don't put non-js files in there, but In my case I have a .gitkeep file in there and in the future I'll possibly have an .eslintrc file in there.

timezone different in server

When start with timezone America/Sao_Paulo in server, sheduler get timezone UTC.

I need execute sheduler in Brazil timezone. How To ?

Use Websockets in Tasks

Please explain how to use adonis WS ( websockets ) to push data using this scheduler i got this error
Ws
.getChannel('channel:*')
.topic('channel:XYZ')
.broadcast('message', 'Message for socket')

TypeError: Cannot read property 'broadcast' of null
at curl.setHeaders.get.then

Cannot Load Tasks In Subdirectory

Due to the several Tasks that should execute to fulfill several aspects of our application, I desired a clean way of organizing our tasks.

In this light, decided to go with organizing similar tasks into subdirectories, only to discover that any task placed in a child directory/subdirectory(e.g. app/tasks/user/SendBirthdayWishes.js) aren't loaded into the scheduler.

Diving into the source code, I discovered that adonis-scheduler picks up only tasks placed directly(one-level down) in app/Tasks alone.

As a solution, we could get all the tasks placed in app/tasks/**/** recursively.

I could submit a PR for this if you desire.

Thanks.

Run schedules without the ./ace command

How can I run the tasks without the ./ace command?
The idea is that I want to make it dependent on an env variable tu run it automatically, without having to type in the command.

Data type error in the population of the logs

When upgrading Adonis to version 5.0.12, the task logs show the following error:

info: [object Object] {"meta":"<message>"}

If someone has an idea that can be or how to solve it, you would be very grateful.

Cannot run migration

I couldn't run migration. The console throw the following error:


Error: Make sure CommandsProvider extends the base command

1 Kernel.addCommand
  /Users/juraboonnom/repo/EkoHBD/node_modules/@adonisjs/ace/src/Kernel/index.js:189

2 commands.forEach
  /Users/juraboonnom/repo/EkoHBD/node_modules/@adonisjs/ignitor/src/Ignitor/index.js:412

3 Ignitor._registerCommands
  /Users/juraboonnom/repo/EkoHBD/node_modules/@adonisjs/ignitor/src/Ignitor/index.js:412

4 Ignitor.fire
  /Users/juraboonnom/repo/EkoHBD/node_modules/@adonisjs/ignitor/src/Ignitor/index.js:754

The I try commenting out the

const commands = [
  // 'adonis-scheduler/providers/CommandsProvider'
]

on the app.js, the migration can be run, but the process does not exit. Hence I couldn't do things like node ace migration:run --force && npm start.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.