New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

adonis-scheduler

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis-scheduler - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

src/Exceptions/index.js

58

package.json
{
"name": "adonis-scheduler",
"version": "3.0.0",
"version": "3.0.1",
"description": "Easy task scheduling for AdonisJS",
"scripts": {
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -R spec test",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha test",
"eslint": "eslint ."
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "standard",
"posttest": "npm run coverage",
"pretest": "npm run lint",
"test": "nyc npm run test:local",
"test:local": "FORCE_COLOR=true node bin/index.js --local",
"test:win": "set FORCE_COLOR=true && node bin/index.js --win"
},

@@ -16,19 +20,31 @@ "author": "Nicholas Rempel <nbrempel@gmail.com>",

"dependencies": {
"@adonisjs/ace": "^4.0.4",
"@adonisjs/fold": "^4.0.2",
"@adonisjs/ignitor": "^1.0.6",
"boxen": "^1.2.1",
"debug": "^3.0.0",
"@adonisjs/generic-exceptions": "^1.0.0",
"debug": "^3.0.1",
"lockfile": "^1.0.3",
"lodash": "^4.17.4",
"ms": "^2.0.0",
"node-schedule": "^1.2.4",
"pluralize": "^6.0.0"
"pify": "^3.0.0",
"pluralize": "^7.0.0"
},
"devDependencies": {
"chai": "^4.1.1",
"@adonisjs/ace": "^4.0.5",
"@adonisjs/fold": "^4.0.2",
"@adonisjs/sink": "^1.0.13",
"coveralls": "^2.13.1",
"eslint": "^4.4.1",
"istanbul": "^0.4.5",
"mocha": "^3.5.0",
"mocha-lcov-reporter": "^1.3.0"
"cz-conventional-changelog": "^2.0.0",
"japa": "^1.0.4",
"japa-cli": "^1.0.1",
"nyc": "^11.1.0",
"semver": "^5.4.1",
"standard": "^10.0.3"
},
"directories": {
"test": "test"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"repository": {

@@ -47,2 +63,14 @@ "type": "git",

},
"nyc": {
"exclude": [
"bin",
"test"
]
},
"standard": {
"globals": [
"use",
"make"
]
},
"files": [

@@ -49,0 +77,0 @@ "LICENSE",

@@ -6,7 +6,44 @@ 'use strict'

class SchedulerProvider extends ServiceProvider {
register () {
/**
* Register the scheduler to the IoC container
* with `Adonis/Addons/Scheduler` namespace.
*
* @method _registerScheduler
*
* @return {void}
*
* @private
*/
_registerScheduler () {
this.app.singleton('Adonis/Addons/Scheduler', () => make(require('../src/Scheduler')))
}
/**
* Register the task to the IoC container
* with `Adonis/Addons/Task` namespace.
*
* @method _registerTask
*
* @return {void}
*
* @private
*/
_registerTask () {
this.app.bind('Adonis/Addons/Task', () => require('../src/Scheduler/Task'))
this.app.alias('Adonis/Addons/Task', 'Task')
}
/**
* Register bindings
*
* @method register
*
* @return {void}
*/
register () {
this._registerScheduler()
this._registerTask()
}
}
module.exports = SchedulerProvider
# Adonis Scheduler Provider
[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Appveyor][appveyor-image]][appveyor-url]
[![Coveralls][coveralls-image]][coveralls-url]
This library provides an easy way to schedule recurring tasks for AdonisJS v4.
> Use branch *adonis-v3* for AdonisJS version 3
> Use branch [adonis-v3](https://github.com/nrempel/adonis-scheduler/tree/adonis-v3) for AdonisJS version 3

@@ -42,3 +47,3 @@ ## Install

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

@@ -49,3 +54,3 @@ 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.

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

@@ -60,1 +65,14 @@ | Name | Required | Type | Static | Description |

Special thanks to the creator(s) of [AdonisJS](http://adonisjs.com/) for creating such a great framework.
[appveyor-image]: https://img.shields.io/appveyor/ci/nrempel/adonis-scheduler/master.svg?style=flat-square
[appveyor-url]: https://ci.appveyor.com/project/nrempel/adonis-scheduler
[npm-image]: https://img.shields.io/npm/v/adonis-scheduler.svg?style=flat-square
[npm-url]: https://npmjs.org/package/adonis-scheduler
[travis-image]: https://img.shields.io/travis/nrempel/adonis-scheduler/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/nrempel/adonis-scheduler
[coveralls-image]: https://coveralls.io/repos/github/nrempel/adonis-scheduler/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/nrempel/adonis-scheduler

@@ -6,3 +6,2 @@ 'use strict'

class MakeTask extends Base {
/**

@@ -9,0 +8,0 @@ * The command signature

@@ -6,3 +6,5 @@ 'use strict'

class Scheduler extends Command {
/**
* @return {Array}
*/
static get inject () {

@@ -12,2 +14,5 @@ return ['Adonis/Addons/Scheduler']

/**
* @param {Object} Scheduler
*/
constructor (Scheduler) {

@@ -18,2 +23,5 @@ super()

/**
* @return {String}
*/
static get signature () {

@@ -23,2 +31,5 @@ return 'run:scheduler'

/**
* @return {String}
*/
static get description () {

@@ -28,2 +39,5 @@ return 'Start the scheduler.'

/**
* @return {void}
*/
async handle () {

@@ -30,0 +44,0 @@ this.scheduler.run()

@@ -7,2 +7,4 @@ 'use strict'

const { ioc } = require('@adonisjs/fold')
const CE = require('../Exceptions')
const Task = require('./Task')

@@ -14,3 +16,5 @@ /**

class Scheduler {
/**
* @return {Array}
*/
static get inject () {

@@ -20,4 +24,7 @@ return ['Adonis/Src/Helpers']

/**
* @param {Object} Helpers
*/
constructor (Helpers) {
this.helpers = Helpers
this.Helpers = Helpers
this.instance = require('node-schedule')

@@ -36,3 +43,3 @@ this.registeredTasks = []

_configureTasksPath () {
this.tasksPath = path.join(this.helpers.appRoot(), 'app', 'Tasks')
this.tasksPath = path.join(this.Helpers.appRoot(), 'app', 'Tasks')
this.tasksPath = path.normalize(this.tasksPath)

@@ -42,55 +49,79 @@ }

/**
* Register scheduled tasks for every task found in app/Tasks
* Load task file
*
* @public
* @param {String} file
* @private
*/
run () {
async _fetchTask (file) {
const filePath = path.join(this.tasksPath, file)
let task
try {
debug('Scan tasks path %s', this.tasksPath)
task = require(filePath)
} catch (e) {
if (e instanceof ReferenceError) {
debug('Unable to import task class <%s>. Is it a valid javascript class?', file)
return
} else {
throw e
}
}
const taskFiles = fs.readdirSync(this.tasksPath)
taskFiles.forEach((file) => {
try {
const filePath = path.join(this.tasksPath, file)
const Task = require(filePath)
// Get instance of task class
const taskInstance = ioc.make(Task)
// Get instance of task class
const taskInstance = ioc.make(task)
// Every task must expose a schedule
if (!Task.schedule) {
throw new Error(`No schedule found for task: ${filePath}`)
}
// Every task must expose a schedule
if (!('schedule' in task)) {
throw CE.RuntimeException.undefinedTaskSchedule(file)
}
// Every task must expose a handle function
if (!taskInstance.handle) {
throw new Error(`No handler found for task: ${filePath}`)
}
// Every task must expose a handle function
if (!('handle' in taskInstance)) {
throw CE.RuntimeException.undefinedTaskHandle(file)
}
// Track currently registered tasks in memory
this.registeredTasks.push(Task)
if (!(taskInstance instanceof Task)) {
throw CE.RuntimeException.undefinedInstanceTask(file)
}
// Register task handler
this.instance.scheduleJob(Task.schedule, taskInstance.handle.bind(taskInstance))
} catch (e) {
if (e instanceof ReferenceError) {
debug('Unable to import task class <%s>. Is it a valid javascript class?', file)
} else {
throw e
}
}
})
debug('scheduler running %d tasks', this.registeredTasks.length)
// Track currently registered tasks in memory
this.registeredTasks.push(taskInstance)
// Before add task to schedule need check & unlock file if exist
const locked = await taskInstance.locker.check()
if (locked) {
await taskInstance.locker.unlock()
}
// Register task handler
this.instance.scheduleJob(task.schedule, taskInstance._run.bind(taskInstance))
}
/**
* Register scheduled tasks for every task found in app/Tasks
*
* @public
*/
async run () {
debug('Scan tasks path %s', this.tasksPath)
let taskFiles
try {
taskFiles = fs.readdirSync(this.tasksPath)
} catch (e) {
// If the directory isn't found, log a message and exit gracefully
if (e.code === 'ENOENT') {
debug('The tasks directory <%s> does not exist. Exiting.', this.tasksPath)
} else {
// If it's some other error, bubble up exception
throw e
throw CE.RuntimeException.notFoundTask(this.tasksPath)
}
throw e
}
for (let taskFile of taskFiles) {
await this._fetchTask(taskFile)
}
debug('scheduler running %d tasks', this.registeredTasks.length)
}
}
module.exports = Scheduler

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc