fix(core): update
This commit is contained in:
parent
4d0fb3eb30
commit
93778e1bcf
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -1,16 +1,16 @@
|
|||||||
# gitzone ci_default
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,60 +18,66 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
audit:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- priv
|
||||||
testSTABLE:
|
|
||||||
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
@ -81,31 +87,35 @@ codequality:
|
|||||||
allow_failure: true
|
allow_failure: true
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -113,5 +123,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
14
package.json
14
package.json
@ -30,13 +30,15 @@
|
|||||||
"luxon": "^1.16.0"
|
"luxon": "^1.16.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_*/**/*",
|
||||||
"assets/*",
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
]
|
]
|
||||||
}
|
}
|
15
readme.md
15
readme.md
@ -8,7 +8,7 @@ handle time in smart ways
|
|||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smarttime/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smarttime/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[![build status](https://gitlab.com/pushrocks/smarttime/badges/master/build.svg)](https://gitlab.com/pushrocks/smarttime/commits/master)
|
[![pipeline status](https://gitlab.com/pushrocks/smarttime/badges/master/pipeline.svg)](https://gitlab.com/pushrocks/smarttime/commits/master)
|
||||||
[![coverage report](https://gitlab.com/pushrocks/smarttime/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smarttime/commits/master)
|
[![coverage report](https://gitlab.com/pushrocks/smarttime/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smarttime/commits/master)
|
||||||
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smarttime.svg)](https://www.npmjs.com/package/@pushrocks/smarttime)
|
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smarttime.svg)](https://www.npmjs.com/package/@pushrocks/smarttime)
|
||||||
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smarttime/badge.svg)](https://snyk.io/test/npm/@pushrocks/smarttime)
|
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smarttime/badge.svg)](https://snyk.io/test/npm/@pushrocks/smarttime)
|
||||||
@ -23,6 +23,7 @@ Use TypeScript for best in class instellisense.
|
|||||||
Smarttime offers smart ways to deal with time.
|
Smarttime offers smart ways to deal with time.
|
||||||
|
|
||||||
### class CronManager
|
### class CronManager
|
||||||
|
|
||||||
This class provides scheduling of functions with a cron syntax
|
This class provides scheduling of functions with a cron syntax
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
@ -30,11 +31,12 @@ import { CronManager } from '@pushrocks/smarrtime';
|
|||||||
const cronManagerInstance = new CronManager();
|
const cronManagerInstance = new CronManager();
|
||||||
cronManagerInstance.addConrjob('* * * * * *', async () => {
|
cronManagerInstance.addConrjob('* * * * * *', async () => {
|
||||||
console.log('hello'); // will log 'hello' to console once every second;
|
console.log('hello'); // will log 'hello' to console once every second;
|
||||||
})
|
});
|
||||||
cronManagerInstance.start();
|
cronManagerInstance.start();
|
||||||
```
|
```
|
||||||
|
|
||||||
### class ExtendedDate
|
### class ExtendedDate
|
||||||
|
|
||||||
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
|
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
|
||||||
|
|
||||||
```TypeScript
|
```TypeScript
|
||||||
@ -42,9 +44,14 @@ import { ExtendedDate } from '@pushrocks/smarttime'
|
|||||||
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
|
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins';
|
||||||
import { CronManager } from './smarttime.classes.cronmanager';
|
import { CronManager } from './smarttime.classes.cronmanager';
|
||||||
|
|
||||||
export type TJobFunction = (() => void) | (() => Promise<any>);
|
export type TJobFunction = (() => void) | (() => Promise<any>);
|
||||||
|
|
||||||
export class CronJob {
|
export class CronJob {
|
||||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||||
public cronExpression: string;
|
public cronExpression: string;
|
||||||
public jobFunction: TJobFunction;
|
public jobFunction: TJobFunction;
|
||||||
|
|
||||||
private cronInterval= plugins.cronParser.parseExpression('* * * * * *');
|
private cronInterval = plugins.cronParser.parseExpression('* * * * * *');
|
||||||
private nextExecutionUnix: number = 0;
|
private nextExecutionUnix: number = 0;
|
||||||
|
|
||||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction ) {
|
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
||||||
this.cronExpression = cronExpressionArg;
|
this.cronExpression = cronExpressionArg;
|
||||||
this.jobFunction = jobFunction;
|
this.jobFunction = jobFunction;
|
||||||
}
|
}
|
||||||
@ -21,12 +21,18 @@ export class CronJob {
|
|||||||
*/
|
*/
|
||||||
public checkExecution() {
|
public checkExecution() {
|
||||||
if (this.nextExecutionUnix === 0) {
|
if (this.nextExecutionUnix === 0) {
|
||||||
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
|
this.nextExecutionUnix = this.cronInterval
|
||||||
|
.next()
|
||||||
|
.toDate()
|
||||||
|
.getTime();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Date.now() > this.nextExecutionUnix) {
|
if (Date.now() > this.nextExecutionUnix) {
|
||||||
this.jobFunction();
|
this.jobFunction();
|
||||||
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
|
this.nextExecutionUnix = this.cronInterval
|
||||||
|
.next()
|
||||||
|
.toDate()
|
||||||
|
.getTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +45,7 @@ export class CronJob {
|
|||||||
this.status = 'stopped';
|
this.status = 'stopped';
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCronInterval () {
|
private getCronInterval() {
|
||||||
return plugins.cronParser.parseExpression(this.cronExpression);
|
return plugins.cronParser.parseExpression(this.cronExpression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,6 @@ export class ExtendedDate extends Date {
|
|||||||
// INSTANCE
|
// INSTANCE
|
||||||
public timezone: TAvailableZone;
|
public timezone: TAvailableZone;
|
||||||
|
|
||||||
|
|
||||||
constructor(unixMilli: number) {
|
constructor(unixMilli: number) {
|
||||||
super(unixMilli);
|
super(unixMilli);
|
||||||
}
|
}
|
||||||
@ -116,10 +115,10 @@ export class ExtendedDate extends Date {
|
|||||||
year: this.getFullYear(),
|
year: this.getFullYear(),
|
||||||
yearString: `${this.getFullYear()}`,
|
yearString: `${this.getFullYear()}`,
|
||||||
month: this.getMonth() + 1,
|
month: this.getMonth() + 1,
|
||||||
monthString: ("0" + (this.getMonth() + 1)).slice(-2),
|
monthString: ('0' + (this.getMonth() + 1)).slice(-2),
|
||||||
monthName: monthsArray[this.getMonth()],
|
monthName: monthsArray[this.getMonth()],
|
||||||
day: this.getDate(),
|
day: this.getDate(),
|
||||||
dayString: ("0" + this.getDate()).slice(-2),
|
dayString: ('0' + this.getDate()).slice(-2),
|
||||||
dayOfTheWeek: this.getDay(),
|
dayOfTheWeek: this.getDay(),
|
||||||
dayOfTheWeekName: daysArray[this.getDay()]
|
dayOfTheWeekName: daysArray[this.getDay()]
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@ import * as plugins from './smarttime.plugins';
|
|||||||
export class Interval {
|
export class Interval {
|
||||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||||
private statusAuthorization: any = null;
|
private statusAuthorization: any = null;
|
||||||
|
|
||||||
public intervalMilliseconds: number;
|
public intervalMilliseconds: number;
|
||||||
public intervalJobs: Array<() => any> = [];
|
public intervalJobs: Array<() => any> = [];
|
||||||
constructor(intervalMillisencondsArg: number) {
|
constructor(intervalMillisencondsArg: number) {
|
||||||
@ -23,7 +23,7 @@ export class Interval {
|
|||||||
runInterval();
|
runInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop () {
|
public stop() {
|
||||||
this.status = 'stopped';
|
this.status = 'stopped';
|
||||||
this.statusAuthorization = null;
|
this.statusAuthorization = null;
|
||||||
}
|
}
|
||||||
@ -32,9 +32,9 @@ export class Interval {
|
|||||||
this.intervalJobs.push(funcArg);
|
this.intervalJobs.push(funcArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private executeIntervalJobs () {
|
private executeIntervalJobs() {
|
||||||
for (const funcArg of this.intervalJobs) {
|
for (const funcArg of this.intervalJobs) {
|
||||||
funcArg();
|
funcArg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user