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
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
@ -1,16 +1,16 @@
|
||||
# gitzone ci_default
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@ -18,60 +18,66 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
audit:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- 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:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
@ -81,31 +87,35 @@ codequality:
|
||||
allow_failure: true
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -113,5 +123,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
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"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"assets/*",
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
}
|
15
readme.md
15
readme.md
@ -8,7 +8,7 @@ handle time in smart ways
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smarttime/)
|
||||
|
||||
## 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)
|
||||
[![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)
|
||||
@ -23,6 +23,7 @@ Use TypeScript for best in class instellisense.
|
||||
Smarttime offers smart ways to deal with time.
|
||||
|
||||
### class CronManager
|
||||
|
||||
This class provides scheduling of functions with a cron syntax
|
||||
|
||||
```typescript
|
||||
@ -30,11 +31,12 @@ import { CronManager } from '@pushrocks/smarrtime';
|
||||
const cronManagerInstance = new CronManager();
|
||||
cronManagerInstance.addConrjob('* * * * * *', async () => {
|
||||
console.log('hello'); // will log 'hello' to console once every second;
|
||||
})
|
||||
});
|
||||
cronManagerInstance.start();
|
||||
```
|
||||
|
||||
### class ExtendedDate
|
||||
|
||||
This class offers static functions to create zone specific JavaScript dates from European formated time strings.
|
||||
|
||||
```TypeScript
|
||||
@ -42,9 +44,14 @@ import { ExtendedDate } from '@pushrocks/smarttime'
|
||||
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.
|
||||
|
||||
> 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 { CronManager } from './smarttime.classes.cronmanager';
|
||||
|
||||
export type TJobFunction = (() => void) | (() => Promise<any>);
|
||||
export type TJobFunction = (() => void) | (() => Promise<any>);
|
||||
|
||||
export class CronJob {
|
||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||
public cronExpression: string;
|
||||
public jobFunction: TJobFunction;
|
||||
|
||||
private cronInterval= plugins.cronParser.parseExpression('* * * * * *');
|
||||
|
||||
private cronInterval = plugins.cronParser.parseExpression('* * * * * *');
|
||||
private nextExecutionUnix: number = 0;
|
||||
|
||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction ) {
|
||||
constructor(cronManager: CronManager, cronExpressionArg: string, jobFunction: TJobFunction) {
|
||||
this.cronExpression = cronExpressionArg;
|
||||
this.jobFunction = jobFunction;
|
||||
}
|
||||
@ -21,12 +21,18 @@ export class CronJob {
|
||||
*/
|
||||
public checkExecution() {
|
||||
if (this.nextExecutionUnix === 0) {
|
||||
this.nextExecutionUnix = this.cronInterval.next().toDate().getTime();
|
||||
this.nextExecutionUnix = this.cronInterval
|
||||
.next()
|
||||
.toDate()
|
||||
.getTime();
|
||||
return;
|
||||
}
|
||||
if (Date.now() > this.nextExecutionUnix) {
|
||||
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';
|
||||
}
|
||||
|
||||
private getCronInterval () {
|
||||
private getCronInterval() {
|
||||
return plugins.cronParser.parseExpression(this.cronExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,6 @@ export class ExtendedDate extends Date {
|
||||
// INSTANCE
|
||||
public timezone: TAvailableZone;
|
||||
|
||||
|
||||
constructor(unixMilli: number) {
|
||||
super(unixMilli);
|
||||
}
|
||||
@ -116,10 +115,10 @@ export class ExtendedDate extends Date {
|
||||
year: this.getFullYear(),
|
||||
yearString: `${this.getFullYear()}`,
|
||||
month: this.getMonth() + 1,
|
||||
monthString: ("0" + (this.getMonth() + 1)).slice(-2),
|
||||
monthString: ('0' + (this.getMonth() + 1)).slice(-2),
|
||||
monthName: monthsArray[this.getMonth()],
|
||||
day: this.getDate(),
|
||||
dayString: ("0" + this.getDate()).slice(-2),
|
||||
dayString: ('0' + this.getDate()).slice(-2),
|
||||
dayOfTheWeek: this.getDay(),
|
||||
dayOfTheWeekName: daysArray[this.getDay()]
|
||||
};
|
||||
|
@ -3,7 +3,7 @@ import * as plugins from './smarttime.plugins';
|
||||
export class Interval {
|
||||
public status: 'started' | 'stopped' | 'initial' = 'initial';
|
||||
private statusAuthorization: any = null;
|
||||
|
||||
|
||||
public intervalMilliseconds: number;
|
||||
public intervalJobs: Array<() => any> = [];
|
||||
constructor(intervalMillisencondsArg: number) {
|
||||
@ -23,7 +23,7 @@ export class Interval {
|
||||
runInterval();
|
||||
}
|
||||
|
||||
public stop () {
|
||||
public stop() {
|
||||
this.status = 'stopped';
|
||||
this.statusAuthorization = null;
|
||||
}
|
||||
@ -32,9 +32,9 @@ export class Interval {
|
||||
this.intervalJobs.push(funcArg);
|
||||
}
|
||||
|
||||
private executeIntervalJobs () {
|
||||
private executeIntervalJobs() {
|
||||
for (const funcArg of this.intervalJobs) {
|
||||
funcArg();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user