cron-runner
Advanced tools
Comparing version 0.0.1 to 0.1.0
# Контрибьюторам | ||
Список контрибьютеров данного проекта доступен по ссылке https://github.com/bem-site/bem-data-source/graphs/contributors. Вы так же можете получить его с помощью команды `git log --pretty=format:"%an <%ae>" | sort -u`. | ||
Список контрибьютеров данного проекта доступен по ссылке https://github.com/bem-site/cron-runner/graphs/contributors. Вы так же можете получить его с помощью команды `git log --pretty=format:"%an <%ae>" | sort -u`. |
54
index.js
var inherit = require('inherit'), | ||
Logger = require('bem-site-logger'), | ||
CronJob = require('cron').CronJob; | ||
@@ -6,4 +7,11 @@ | ||
_STATE: { | ||
IDLE: 0, | ||
ACTIVE: 1 | ||
}, | ||
_job: undefined, | ||
_options: undefined, | ||
_logger: undefined, | ||
_state: undefined, | ||
@@ -20,2 +28,3 @@ /** | ||
this._options = options; | ||
this._logger = Logger.createLogger(module); | ||
@@ -34,2 +43,4 @@ if (!this._options) { | ||
this._state = this._STATE.IDLE; | ||
o.startImmediately = o.startImmediately || false; | ||
@@ -45,16 +56,33 @@ this._job = new CronJob({ | ||
/** | ||
* Optional logging if debug options is set to true | ||
* @private | ||
* Switches state to IDLE state | ||
* @returns {exports} | ||
*/ | ||
_log: function () { | ||
if (this._options.cron.debug) { | ||
console.log(arguments); | ||
} | ||
setIdle: function () { | ||
this._state = this._STATE.IDLE; | ||
return this; | ||
}, | ||
/** | ||
* Switches state to ACTIVE state | ||
* @returns {exports} | ||
*/ | ||
setActive: function () { | ||
this._state = this._STATE.ACTIVE; | ||
return this; | ||
}, | ||
/** | ||
* Checks is current state is ACTIVE state | ||
* @returns {boolean} | ||
*/ | ||
isActive: function () { | ||
return this._state === this._STATE.ACTIVE; | ||
}, | ||
/** | ||
* Method for cron script execution | ||
*/ | ||
execute: function () { | ||
console.log('execute'); | ||
this._logger.info('cron runner start execute'); | ||
return true; | ||
}, | ||
@@ -68,6 +96,8 @@ | ||
if (!this._job) { | ||
throw new Error('Cron job has\'t been initialized yet'); | ||
var error = new Error('Cron job has\'t been initialized yet'); | ||
this._logger.error(error.message); | ||
throw error; | ||
} | ||
this._log('Start cron job'); | ||
this._logger.info('Start cron job'); | ||
this._job.start(); | ||
@@ -83,6 +113,8 @@ return this; | ||
if (!this._job) { | ||
throw new Error('Cron job has\'t been initialized yet'); | ||
var error = new Error('Cron job has\'t been initialized yet'); | ||
this._logger.error(error.message); | ||
throw error; | ||
} | ||
this._log('Stop cron job'); | ||
this._logger.info('Stop cron job'); | ||
this._job.stop(); | ||
@@ -89,0 +121,0 @@ return this; |
{ | ||
"name": "cron-runner", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -16,2 +16,8 @@ "type": "git", | ||
], | ||
"keywords": [ | ||
"cron", | ||
"bem-site", | ||
"inherit", | ||
"runner" | ||
], | ||
"engines": { | ||
@@ -21,5 +27,5 @@ "node": ">= 0.8.0" | ||
"dependencies": { | ||
"inherit": "^2.2.x", | ||
"lodash": "^3.1.x", | ||
"cron": "1.0.5" | ||
"bem-site-logger": "^0.0.x", | ||
"cron": "1.0.5", | ||
"inherit": "^2.2.x" | ||
}, | ||
@@ -38,3 +44,3 @@ "devDependencies": { | ||
"codestyle": "node_modules/.bin/jshint . && node_modules/.bin/jscs -c .jscs.js .", | ||
"cover": "istanbul cover _mocha", | ||
"cover": "NODE_ENV=testing istanbul cover _mocha", | ||
"coveralls": "npm install coveralls && npm run cover && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", | ||
@@ -41,0 +47,0 @@ "test": "npm run coveralls" |
@@ -11,2 +11,3 @@ # cron-runner | ||
![GitHub Logo](./logo.png) | ||
@@ -40,3 +41,27 @@ ## Usage | ||
``` | ||
You can receive more details about cron patterns configuration [here](https://www.npmjs.com/package/cron). | ||
### API | ||
#### setIdle | ||
Switches state of runner to IDLE state. You can call it after your custom execution code for unlock | ||
next execution calls. | ||
#### setActive | ||
Switches state of runner to ACTIVE state. You can call it before your custom execution code for lock | ||
next execution calls if current execution has not performed yet. | ||
#### isActive | ||
Returns `true` if cron runner is in ACTIVE state. Otherwise returns `false`. | ||
#### execute | ||
Normally you should override this methods in you CronRunner inheritance and write your custom code | ||
#### start | ||
Performs start of running cron tasks. | ||
#### stop | ||
Performs stop of running cron tasks. | ||
## Testing | ||
@@ -43,0 +68,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76396
6
101
84
+ Addedbem-site-logger@^0.0.x
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedbem-site-logger@0.0.5(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedmoment@2.30.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
- Removedlodash@^3.1.x
- Removedlodash@3.10.1(transitive)