Comparing version 9.0.3 to 9.0.5
@@ -7,2 +7,4 @@ let Cerobee = require('clerobee') | ||
const CronJob = require('cron').CronJob | ||
module.exports = function (self) { | ||
@@ -45,2 +47,21 @@ return { | ||
}, | ||
startCron: function ( name, spec, fn ) { | ||
var self = this | ||
let cj = new CronJob(spec, function () { | ||
fn().catch( self.harconlog ) | ||
} ) | ||
cj.start() | ||
if (self.firestarter.cronjobRefs[name]) | ||
throw new Error('CronJob already exists with the name of ' + name) | ||
self.firestarter.cronjobRefs[name] = cj | ||
return cj | ||
}, | ||
stopCron: function (name) { | ||
if (self.firestarter.cronjobRefs[name]) | ||
try { | ||
self.firestarter.cronjobRefs[name].stop() | ||
delete self.firestarter.cronjobRefs[name] | ||
} catch (err) { this.harconlog(err) } | ||
return OK | ||
}, | ||
setTimeout: function ( fn, timeout ) { | ||
@@ -47,0 +68,0 @@ var self = this |
let Firestarter = require('./Firestarter') | ||
let ignorable = [ 'init', 'ignite', 'request', 'inform', 'delegate', 'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval' ] | ||
let ignorable = [ 'init', 'ignite', 'request', 'inform', 'delegate', 'startCron', 'stopCron', 'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval' ] | ||
@@ -71,2 +71,3 @@ let _ = require('isa.js') | ||
this.cronjobRefs = {} | ||
this.timeoutRefs = [] | ||
@@ -143,9 +144,17 @@ this.intervalRefs = [] | ||
self.timeoutRefs.forEach( function (ref) { | ||
for (let name in self.cronjobRefs) { | ||
try { | ||
self.cronjobRefs[name].stop() | ||
} catch ( err ) { self.harconlog(err) } | ||
} | ||
self.cronjobRefs = {} | ||
for (let ref of self.timeoutRefs) { | ||
clearTimeout(ref) | ||
} ) | ||
} | ||
self.timeoutRefs.length = 0 | ||
self.intervalRefs.forEach( function (ref) { | ||
for (let ref of self.intervalRefs) { | ||
clearInterval(ref) | ||
} ) | ||
} | ||
self.intervalRefs.length = 0 | ||
@@ -152,0 +161,0 @@ |
{ | ||
"name": "harcon", | ||
"version": "9.0.3", | ||
"version": "9.0.5", | ||
"description": "Messaging/Service Bus for the harmonic convergence of node-based enterprise entities.", | ||
@@ -26,2 +26,3 @@ "keywords": [ | ||
"clerobee": "^0.9.8", | ||
"cron": "^1.6.0", | ||
"harcon-flow": "^2.6.12", | ||
@@ -28,0 +29,0 @@ "isa.js": "^2.2.3", |
@@ -1081,2 +1081,19 @@ Harcon - Proven and reliable microservice solution for the harmonic convergence of JS entities. | ||
## Timing | ||
Each entity published possesses functions to aid timing services: | ||
```javascript | ||
startCron: function ( name, spec, fn ) ... | ||
setTimeout: function ( fn, timeout ) ... | ||
setInterval: function ( fn, interval ) ... | ||
``` | ||
The function startCron creates a cron-like job specified in the 2nd parameter. | ||
The functions setTimeout and setInterval are the wrapped version of the original ones defined by the JS. | ||
Please note,that __all functions must be async__! | ||
All scheduled functions are stopped automatically when [harcon](https://github.com/imrefazekas/harcon) stops. | ||
## License | ||
@@ -1086,3 +1103,3 @@ | ||
Copyright (c) 2017 Imre Fazekas | ||
Copyright (c) 2018 Imre Fazekas | ||
@@ -1089,0 +1106,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of |
@@ -15,3 +15,3 @@ var funcTag = '[object Function]' | ||
let ignorable = [ 'init', 'ignite', 'request', 'inform', 'delegate', 'erupt', 'setTimeout', 'setInterval' ] | ||
let ignorable = [ 'init', 'ignite', 'request', 'inform', 'delegate', 'erupt', 'setCron', 'setTimeout', 'setInterval' ] | ||
@@ -18,0 +18,0 @@ function functions (obj) { |
@@ -77,6 +77,5 @@ let fs = require('fs') | ||
self.setInterval( function () { | ||
self.setInterval( async function () { | ||
self.harconlog( null, 'Mortar is checking for entity changes', null, 'trace' ) | ||
self.igniteFiles( ).then( () => {} ) | ||
.catch( self.harconlog ) | ||
return self.igniteFiles( ) | ||
}, self.options.liveReloadTimeout || 5000 ) | ||
@@ -83,0 +82,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
642116
4086
1125
8
+ Addedcron@^1.6.0
+ Addedcron@1.8.3(transitive)
+ Addedluxon@1.28.1(transitive)