Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
f50384947d | |||
65c1dd8fdc | |||
613d46bb38 | |||
439da1f342 |
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -36,6 +39,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/taskbuffer",
|
"name": "@pushrocks/taskbuffer",
|
||||||
"version": "2.1.15",
|
"version": "2.1.17",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/taskbuffer",
|
"name": "@pushrocks/taskbuffer",
|
||||||
"version": "2.1.15",
|
"version": "2.1.17",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^5.0.0",
|
"@pushrocks/lik": "^5.0.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/taskbuffer",
|
"name": "@pushrocks/taskbuffer",
|
||||||
"version": "2.1.15",
|
"version": "2.1.17",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "flexible task management. TypeScript ready!",
|
"description": "flexible task management. TypeScript ready!",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -18,8 +18,10 @@ tap.test('should run the task as expected', async () => {
|
|||||||
myTaskManager.addTask(
|
myTaskManager.addTask(
|
||||||
new taskbuffer.Task({
|
new taskbuffer.Task({
|
||||||
name: 'myTask',
|
name: 'myTask',
|
||||||
|
bufferMax: 1,
|
||||||
|
buffered: true,
|
||||||
taskFunction: async () => {
|
taskFunction: async () => {
|
||||||
console.log('Task executed!');
|
console.log('Task "myTask" executed!');
|
||||||
referenceBoolean = true;
|
referenceBoolean = true;
|
||||||
taskRunCounter++;
|
taskRunCounter++;
|
||||||
if (taskRunCounter === 10) {
|
if (taskRunCounter === 10) {
|
||||||
@ -35,7 +37,7 @@ tap.test('should run the task as expected', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should schedule task', async () => {
|
tap.test('should schedule task', async () => {
|
||||||
myTaskManager.scheduleTaskByName('myTask', '* * * * * *');
|
myTaskManager.scheduleTaskByName('myTask', '*/10 * * * * *');
|
||||||
await taskDone.promise;
|
await taskDone.promise;
|
||||||
myTaskManager.descheduleTaskByName('myTask');
|
myTaskManager.descheduleTaskByName('myTask');
|
||||||
});
|
});
|
||||||
|
@ -18,7 +18,7 @@ tap.test('should run buffered', async (tools) => {
|
|||||||
bufferMax: 1,
|
bufferMax: 1,
|
||||||
afterTask: () => {
|
afterTask: () => {
|
||||||
return task2;
|
return task2;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
const task2 = new taskbuffer.Task({
|
const task2 = new taskbuffer.Task({
|
||||||
name: 'a buffered task',
|
name: 'a buffered task',
|
||||||
@ -31,7 +31,7 @@ tap.test('should run buffered', async (tools) => {
|
|||||||
bufferMax: 1,
|
bufferMax: 1,
|
||||||
afterTask: () => {
|
afterTask: () => {
|
||||||
return task3;
|
return task3;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
const task3 = new taskbuffer.Task({
|
const task3 = new taskbuffer.Task({
|
||||||
name: 'a buffered task',
|
name: 'a buffered task',
|
||||||
@ -41,12 +41,12 @@ tap.test('should run buffered', async (tools) => {
|
|||||||
console.log(`task3 ran ${counter3} times`);
|
console.log(`task3 ran ${counter3} times`);
|
||||||
},
|
},
|
||||||
buffered: true,
|
buffered: true,
|
||||||
bufferMax: 1
|
bufferMax: 1,
|
||||||
});
|
});
|
||||||
while(counter1 < 10) {
|
while (counter1 < 10) {
|
||||||
await tools.delayFor(5000);
|
await tools.delayFor(5000);
|
||||||
task.trigger();
|
task.trigger();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -58,6 +58,7 @@ export class Task {
|
|||||||
taskArg: Task | TPreOrAfterTaskFunction,
|
taskArg: Task | TPreOrAfterTaskFunction,
|
||||||
optionsArg: { x?: any; touchedTasksArray?: Task[] }
|
optionsArg: { x?: any; touchedTasksArray?: Task[] }
|
||||||
) => {
|
) => {
|
||||||
|
// extracts the task in case it is specified as a return value of a function
|
||||||
const taskToRun = Task.extractTask(taskArg);
|
const taskToRun = Task.extractTask(taskArg);
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ export class Task {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
// man datory properties
|
// mandatory properties
|
||||||
public name: string;
|
public name: string;
|
||||||
public taskFunction: ITaskFunction;
|
public taskFunction: ITaskFunction;
|
||||||
public buffered: boolean;
|
public buffered: boolean;
|
||||||
|
@ -70,7 +70,15 @@ export class TaskManager {
|
|||||||
public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
|
public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
|
||||||
const taskToSchedule = this.getTaskByName(taskNameArg);
|
const taskToSchedule = this.getTaskByName(taskNameArg);
|
||||||
const cronJob = this.cronJobManager.addCronjob(cronStringArg, async () => {
|
const cronJob = this.cronJobManager.addCronjob(cronStringArg, async () => {
|
||||||
await taskToSchedule.triggerBuffered();
|
console.log(`taskbuffer schedule triggered task >>${taskToSchedule.name}<<`);
|
||||||
|
console.log(
|
||||||
|
`task >>${taskToSchedule.name}<< is ${
|
||||||
|
taskToSchedule.buffered
|
||||||
|
? `buffered with max ${taskToSchedule.bufferMax} buffered calls`
|
||||||
|
: `unbuffered`
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
await taskToSchedule.trigger();
|
||||||
});
|
});
|
||||||
taskToSchedule.cronJob = cronJob;
|
taskToSchedule.cronJob = cronJob;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user