Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
743c9fb847 | |||
ac2edd6d74 | |||
725102d02c | |||
7c73579c9f | |||
a1996ea1bd | |||
dc92ae7140 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"version": "3.0.22",
|
"version": "3.0.25",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.22",
|
"version": "3.0.25",
|
||||||
"description": "handle time in smart ways",
|
"description": "handle time in smart ways",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export * from './smarttime.classes.cronmanager';
|
export * from './smarttime.classes.cronmanager';
|
||||||
|
export * from './smarttime.classes.cronjob';
|
||||||
export * from './smarttime.classes.extendeddate';
|
export * from './smarttime.classes.extendeddate';
|
||||||
export * from './smarttime.classes.hrtmeasurement';
|
export * from './smarttime.classes.hrtmeasurement';
|
||||||
export * from './smarttime.classes.interval';
|
export * from './smarttime.classes.interval';
|
||||||
|
@ -28,37 +28,48 @@ export class CronManager {
|
|||||||
* starts the cronjob
|
* starts the cronjob
|
||||||
*/
|
*/
|
||||||
public start() {
|
public start() {
|
||||||
this.status = 'started';
|
if (this.status !== 'started') {
|
||||||
for (const cronJob of this.cronjobs.getArray()) {
|
this.status = 'started';
|
||||||
cronJob.start();
|
for (const cronJob of this.cronjobs.getArray()) {
|
||||||
}
|
cronJob.start();
|
||||||
this.executionTimeout = new plugins.smartdelay.Timeout(0);
|
}
|
||||||
|
this.executionTimeout = new plugins.smartdelay.Timeout(0);
|
||||||
|
|
||||||
// recursion
|
// recursion
|
||||||
const runCheckExecution = () => {
|
const runCheckExecution = () => {
|
||||||
console.log(`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`);
|
console.log(
|
||||||
this.executionTimeout.promise.then(() => {
|
`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`
|
||||||
let timeToNextOverallExecution: number;
|
);
|
||||||
for (const cronJob of this.cronjobs.getArray()) {
|
this.executionTimeout.promise.then(() => {
|
||||||
const timeToNextJobExecution = cronJob.checkExecution();
|
let timeToNextOverallExecution: number;
|
||||||
if (timeToNextJobExecution < timeToNextOverallExecution || !timeToNextOverallExecution) {
|
for (const cronJob of this.cronjobs.getArray()) {
|
||||||
timeToNextOverallExecution = timeToNextJobExecution;
|
const timeToNextJobExecution = cronJob.checkExecution();
|
||||||
|
if (
|
||||||
|
timeToNextJobExecution < timeToNextOverallExecution ||
|
||||||
|
!timeToNextOverallExecution
|
||||||
|
) {
|
||||||
|
timeToNextOverallExecution = timeToNextJobExecution;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
this.executionTimeout = new plugins.smartdelay.Timeout(timeToNextOverallExecution);
|
||||||
this.executionTimeout = new plugins.smartdelay.Timeout(timeToNextOverallExecution);
|
runCheckExecution();
|
||||||
runCheckExecution();
|
});
|
||||||
});
|
};
|
||||||
};
|
|
||||||
|
|
||||||
runCheckExecution();
|
runCheckExecution();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stops all cronjobs
|
* stops all cronjobs
|
||||||
*/
|
*/
|
||||||
public stop() {
|
public stop() {
|
||||||
this.status = 'stopped';
|
if (this.status === 'started') {
|
||||||
this.executionTimeout.cancel();
|
this.status = 'stopped';
|
||||||
|
this.executionTimeout.cancel();
|
||||||
|
} else {
|
||||||
|
console.log(`You tried to stop a CronManager that was not actually started.`);
|
||||||
|
}
|
||||||
for (const cron of this.cronjobs.getArray()) {
|
for (const cron of this.cronjobs.getArray()) {
|
||||||
cron.stop();
|
cron.stop();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user