fix(core): update
This commit is contained in:
parent
419fe80bde
commit
76768a1307
14625
package-lock.json
generated
14625
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -27,7 +27,8 @@
|
|||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"croner": "^1.1.23",
|
"croner": "^1.1.23",
|
||||||
"dayjs": "^1.9.1",
|
"dayjs": "^1.9.1",
|
||||||
"is-nan": "^1.3.0"
|
"is-nan": "^1.3.0",
|
||||||
|
"pretty-ms": "^7.0.1"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -17,7 +17,7 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
let counter2 = 0;
|
let counter2 = 0;
|
||||||
let counter3 = 0;
|
let counter3 = 0;
|
||||||
const cronJob = testCronManager.addCronjob('*/2 * * * * *', async () => {
|
const cronJob = testCronManager.addCronjob('*/2 * * * * *', async () => {
|
||||||
if (counter === 10) {
|
if (counter === 5) {
|
||||||
testCronManager.removeCronjob(cronJob);
|
testCronManager.removeCronjob(cronJob);
|
||||||
done.resolve();
|
done.resolve();
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
console.log(`${new Date().getSeconds()} hey ${counter} -> runs every 2 seconds`);
|
console.log(`${new Date().getSeconds()} hey ${counter} -> runs every 2 seconds`);
|
||||||
});
|
});
|
||||||
const cronJob2 = testCronManager.addCronjob('*/3 * * * * *', async () => {
|
const cronJob2 = testCronManager.addCronjob('*/3 * * * * *', async () => {
|
||||||
if (counter2 === 10) {
|
if (counter2 === 5) {
|
||||||
testCronManager.removeCronjob(cronJob2);
|
testCronManager.removeCronjob(cronJob2);
|
||||||
done2.resolve();
|
done2.resolve();
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
console.log(`${new Date().getSeconds()} hey ${counter2} -> runs every 3 seconds`);
|
console.log(`${new Date().getSeconds()} hey ${counter2} -> runs every 3 seconds`);
|
||||||
});
|
});
|
||||||
const cronJob3 = testCronManager.addCronjob('*/4 * * * * *', async () => {
|
const cronJob3 = testCronManager.addCronjob('*/4 * * * * *', async () => {
|
||||||
if (counter3 === 10) {
|
if (counter3 === 5) {
|
||||||
done3.resolve();
|
done3.resolve();
|
||||||
}
|
}
|
||||||
counter3++;
|
counter3++;
|
||||||
|
@ -2,6 +2,11 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
|
|
||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index';
|
||||||
|
|
||||||
|
tap.test('should create a valid JavaScript Date', async () => {
|
||||||
|
const extendedDate = new smarttime.ExtendedDate(Date.now());
|
||||||
|
console.log(extendedDate);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
||||||
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
|
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
|
||||||
console.log(extendedDate);
|
console.log(extendedDate);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins';
|
||||||
import { CronJob } from './smarttime.classes.cronjob';
|
import { CronJob } from './smarttime.classes.cronjob';
|
||||||
|
import { getMilliSecondsAsHumanReadableString } from './smarttime.units';
|
||||||
|
|
||||||
export class CronManager {
|
export class CronManager {
|
||||||
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
public executionTimeout: plugins.smartdelay.Timeout<void>;
|
||||||
@ -47,16 +48,19 @@ export class CronManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextRunningCronjob) {
|
if (nextRunningCronjob) {
|
||||||
this.executionTimeout = new plugins.smartdelay.Timeout(nextRunningCronjob.getTimeToNextExecution());
|
this.executionTimeout = new plugins.smartdelay.Timeout(
|
||||||
|
nextRunningCronjob.getTimeToNextExecution()
|
||||||
|
);
|
||||||
console.log(
|
console.log(
|
||||||
`Next CronJob scheduled in ${this.executionTimeout.getTimeLeft()} milliseconds`
|
`Next CronJob scheduled in ${getMilliSecondsAsHumanReadableString(
|
||||||
|
this.executionTimeout.getTimeLeft()
|
||||||
|
)}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.executionTimeout = new plugins.smartdelay.Timeout(1000);
|
this.executionTimeout = new plugins.smartdelay.Timeout(1000);
|
||||||
console.log('no cronjobs specified! Checking again in 1 second');
|
console.log('no cronjobs specified! Checking again in 1 second');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await this.executionTimeout.promise;
|
await this.executionTimeout.promise;
|
||||||
} while (this.status === 'started');
|
} while (this.status === 'started');
|
||||||
};
|
};
|
||||||
|
@ -73,7 +73,7 @@ export class ExtendedDate extends Date {
|
|||||||
// INSTANCE
|
// INSTANCE
|
||||||
public timezone: TAvailableZone;
|
public timezone: TAvailableZone;
|
||||||
|
|
||||||
constructor(unixMilli: number) {
|
constructor(unixMilli: number = Date.now()) {
|
||||||
super(unixMilli);
|
super(unixMilli);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ export class TimeStamp {
|
|||||||
/**
|
/**
|
||||||
* returns new TimeStamp from milliseconds
|
* returns new TimeStamp from milliseconds
|
||||||
*/
|
*/
|
||||||
public static fromMilliSeconds(milliSecondsArg) {
|
public static fromMilliSeconds(milliSecondsArg: number) {
|
||||||
return new TimeStamp(milliSecondsArg);
|
return new TimeStamp(milliSecondsArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,11 +5,12 @@ import * as smartpromise from '@pushrocks/smartpromise';
|
|||||||
|
|
||||||
export { lik, smartdelay, smartpromise };
|
export { lik, smartdelay, smartpromise };
|
||||||
|
|
||||||
// third parties
|
// third parties;
|
||||||
import croner from 'croner';
|
const croner: any = require('croner');
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import isToday from 'dayjs/plugin/isToday';
|
import isToday from 'dayjs/plugin/isToday';
|
||||||
|
import prettyMs from 'pretty-ms';
|
||||||
|
|
||||||
dayjs.extend(isToday);
|
dayjs.extend(isToday);
|
||||||
|
|
||||||
export { croner, dayjs };
|
export { croner, dayjs, prettyMs };
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import * as plugins from './smarttime.plugins';
|
||||||
|
|
||||||
export let units = {
|
export let units = {
|
||||||
years: (timesArg = 1): number => {
|
years: (timesArg = 1): number => {
|
||||||
return timesArg * 3.154e10;
|
return timesArg * 3.154e10;
|
||||||
@ -30,7 +32,7 @@ export interface IUnitCombinationArg {
|
|||||||
|
|
||||||
export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
||||||
let timeInMilliseconds = 0;
|
let timeInMilliseconds = 0;
|
||||||
let addMilliSeconds = (milliSecondsArg) => {
|
let addMilliSeconds = (milliSecondsArg: number) => {
|
||||||
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
timeInMilliseconds = timeInMilliseconds + milliSecondsArg;
|
||||||
};
|
};
|
||||||
if (combinationArg.years) {
|
if (combinationArg.years) {
|
||||||
@ -54,3 +56,7 @@ export let getMilliSecondsFromUnits = (combinationArg: IUnitCombinationArg) => {
|
|||||||
|
|
||||||
return timeInMilliseconds;
|
return timeInMilliseconds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getMilliSecondsAsHumanReadableString = (milliSecondsArg: number): string => {
|
||||||
|
return plugins.prettyMs(milliSecondsArg);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user