@push.rocks/taskbuffer 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_bundle/bundle.js +55 -88
- package/dist_bundle/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/taskbuffer.classes.distributedcoordinator.d.ts +6 -15
- package/dist_ts/taskbuffer.classes.distributedcoordinator.js +1 -1
- package/dist_ts/taskbuffer.classes.taskmanager.d.ts +12 -48
- package/dist_ts/taskbuffer.classes.taskmanager.js +57 -88
- package/package.json +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/taskbuffer.classes.distributedcoordinator.ts +7 -15
- package/ts/taskbuffer.classes.taskmanager.ts +62 -98
package/dist_bundle/bundle.js
CHANGED
|
@@ -6130,134 +6130,101 @@ var AbstractDistributedCoordinator = class {
|
|
|
6130
6130
|
|
|
6131
6131
|
// ts/taskbuffer.classes.taskmanager.ts
|
|
6132
6132
|
var TaskManager = class {
|
|
6133
|
-
constructor(
|
|
6133
|
+
constructor(options = {}) {
|
|
6134
6134
|
this.randomId = isounique2.uni();
|
|
6135
6135
|
this.taskMap = new dist_ts_exports5.ObjectMap();
|
|
6136
6136
|
this.cronJobManager = new dist_ts_exports6.CronManager();
|
|
6137
6137
|
this.options = {
|
|
6138
6138
|
distributedCoordinator: null
|
|
6139
6139
|
};
|
|
6140
|
-
this.options = Object.assign(this.options,
|
|
6140
|
+
this.options = Object.assign(this.options, options);
|
|
6141
6141
|
}
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
* @param taskNameArg
|
|
6145
|
-
*/
|
|
6146
|
-
getTaskByName(taskNameArg) {
|
|
6147
|
-
return this.taskMap.findSync((itemArg) => {
|
|
6148
|
-
return itemArg.name === taskNameArg;
|
|
6149
|
-
});
|
|
6142
|
+
getTaskByName(taskName) {
|
|
6143
|
+
return this.taskMap.findSync((task) => task.name === taskName);
|
|
6150
6144
|
}
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
*/
|
|
6155
|
-
addTask(taskArg) {
|
|
6156
|
-
if (!taskArg.name) {
|
|
6157
|
-
throw new Error("taskArg needs a name to be added to taskManager");
|
|
6145
|
+
addTask(task) {
|
|
6146
|
+
if (!task.name) {
|
|
6147
|
+
throw new Error("Task must have a name to be added to taskManager");
|
|
6158
6148
|
}
|
|
6159
|
-
this.taskMap.add(
|
|
6149
|
+
this.taskMap.add(task);
|
|
6160
6150
|
}
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
* @param cronStringArg
|
|
6165
|
-
*/
|
|
6166
|
-
addAndScheduleTask(taskArg, cronStringArg) {
|
|
6167
|
-
this.addTask(taskArg);
|
|
6168
|
-
this.scheduleTaskByName(taskArg.name, cronStringArg);
|
|
6151
|
+
addAndScheduleTask(task, cronString) {
|
|
6152
|
+
this.addTask(task);
|
|
6153
|
+
this.scheduleTaskByName(task.name, cronString);
|
|
6169
6154
|
}
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
* @param taskNameArg
|
|
6173
|
-
*/
|
|
6174
|
-
triggerTaskByName(taskNameArg) {
|
|
6175
|
-
const taskToTrigger = this.getTaskByName(taskNameArg);
|
|
6155
|
+
async triggerTaskByName(taskName) {
|
|
6156
|
+
const taskToTrigger = this.getTaskByName(taskName);
|
|
6176
6157
|
if (!taskToTrigger) {
|
|
6177
|
-
throw new Error(`
|
|
6158
|
+
throw new Error(`No task with the name ${taskName} found.`);
|
|
6178
6159
|
}
|
|
6179
6160
|
return taskToTrigger.trigger();
|
|
6180
6161
|
}
|
|
6181
6162
|
async triggerTask(task) {
|
|
6182
6163
|
return task.trigger();
|
|
6183
6164
|
}
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6165
|
+
scheduleTaskByName(taskName, cronString) {
|
|
6166
|
+
const taskToSchedule = this.getTaskByName(taskName);
|
|
6167
|
+
if (!taskToSchedule) {
|
|
6168
|
+
throw new Error(`No task with the name ${taskName} found.`);
|
|
6169
|
+
}
|
|
6170
|
+
this.handleTaskScheduling(taskToSchedule, cronString);
|
|
6171
|
+
}
|
|
6172
|
+
handleTaskScheduling(task, cronString) {
|
|
6190
6173
|
const cronJob = this.cronJobManager.addCronjob(
|
|
6191
|
-
|
|
6192
|
-
async (
|
|
6193
|
-
|
|
6194
|
-
console.log(
|
|
6195
|
-
`task >>${taskToSchedule.name}<< is ${taskToSchedule.buffered ? `buffered with max ${taskToSchedule.bufferMax} buffered calls` : `unbuffered`}`
|
|
6196
|
-
);
|
|
6174
|
+
cronString,
|
|
6175
|
+
async (triggerTime) => {
|
|
6176
|
+
this.logTaskState(task);
|
|
6197
6177
|
if (this.options.distributedCoordinator) {
|
|
6198
|
-
|
|
6199
|
-
const announcementResult = await this.options.distributedCoordinator.fireDistributedTaskRequest({
|
|
6200
|
-
submitterRandomId: this.randomId,
|
|
6201
|
-
status: "requesting",
|
|
6202
|
-
taskExecutionParallel: 1,
|
|
6203
|
-
taskExecutionTime: triggerTimeArg,
|
|
6204
|
-
taskExecutionTimeout: taskToSchedule.timeout,
|
|
6205
|
-
taskName: taskToSchedule.name,
|
|
6206
|
-
taskVersion: taskToSchedule.version
|
|
6207
|
-
});
|
|
6178
|
+
const announcementResult = await this.performDistributedConsultation(task, triggerTime);
|
|
6208
6179
|
if (!announcementResult.shouldTrigger) {
|
|
6209
|
-
console.log("
|
|
6180
|
+
console.log("Distributed coordinator result: NOT EXECUTING");
|
|
6210
6181
|
return;
|
|
6211
6182
|
} else {
|
|
6212
|
-
console.log("
|
|
6183
|
+
console.log("Distributed coordinator result: CHOSEN AND EXECUTING");
|
|
6213
6184
|
}
|
|
6214
6185
|
}
|
|
6215
|
-
await
|
|
6186
|
+
await task.trigger();
|
|
6216
6187
|
}
|
|
6217
6188
|
);
|
|
6218
|
-
|
|
6189
|
+
task.cronJob = cronJob;
|
|
6190
|
+
}
|
|
6191
|
+
logTaskState(task) {
|
|
6192
|
+
console.log(`Taskbuffer schedule triggered task >>${task.name}<<`);
|
|
6193
|
+
const bufferState = task.buffered ? `buffered with max ${task.bufferMax} buffered calls` : `unbuffered`;
|
|
6194
|
+
console.log(`Task >>${task.name}<< is ${bufferState}`);
|
|
6195
|
+
}
|
|
6196
|
+
async performDistributedConsultation(task, triggerTime) {
|
|
6197
|
+
console.log("Found a distributed coordinator, performing consultation.");
|
|
6198
|
+
return this.options.distributedCoordinator.fireDistributedTaskRequest({
|
|
6199
|
+
submitterId: this.randomId,
|
|
6200
|
+
status: "requesting",
|
|
6201
|
+
taskExecutionParallel: 1,
|
|
6202
|
+
taskExecutionTime: triggerTime,
|
|
6203
|
+
taskExecutionTimeout: task.timeout,
|
|
6204
|
+
taskName: task.name,
|
|
6205
|
+
taskVersion: task.version
|
|
6206
|
+
});
|
|
6219
6207
|
}
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
const taskToDeSchedule = this.getTaskByName(taskNameArg);
|
|
6226
|
-
if (taskToDeSchedule.cronJob) {
|
|
6227
|
-
this.cronJobManager.removeCronjob(taskToDeSchedule.cronJob);
|
|
6228
|
-
taskToDeSchedule.cronJob = null;
|
|
6208
|
+
descheduleTaskByName(taskName) {
|
|
6209
|
+
const task = this.getTaskByName(taskName);
|
|
6210
|
+
if (task && task.cronJob) {
|
|
6211
|
+
this.cronJobManager.removeCronjob(task.cronJob);
|
|
6212
|
+
task.cronJob = null;
|
|
6229
6213
|
}
|
|
6230
6214
|
if (this.cronJobManager.cronjobs.isEmpty) {
|
|
6231
6215
|
this.cronJobManager.stop();
|
|
6232
6216
|
}
|
|
6233
6217
|
}
|
|
6234
|
-
/**
|
|
6235
|
-
* deschedules a task
|
|
6236
|
-
* @param task
|
|
6237
|
-
*/
|
|
6238
6218
|
async descheduleTask(task) {
|
|
6239
6219
|
await this.descheduleTaskByName(task.name);
|
|
6240
6220
|
}
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
*/
|
|
6245
|
-
getScheduleForTaskName(taskNameArg) {
|
|
6246
|
-
const task = this.getTaskByName(taskNameArg);
|
|
6247
|
-
if (!task || !task.cronJob) {
|
|
6248
|
-
return null;
|
|
6249
|
-
}
|
|
6250
|
-
return task.cronJob.cronExpression;
|
|
6221
|
+
getScheduleForTaskName(taskName) {
|
|
6222
|
+
const task = this.getTaskByName(taskName);
|
|
6223
|
+
return task && task.cronJob ? task.cronJob.cronExpression : null;
|
|
6251
6224
|
}
|
|
6252
|
-
/**
|
|
6253
|
-
* starts the taskmanager
|
|
6254
|
-
*/
|
|
6255
6225
|
start() {
|
|
6256
6226
|
this.cronJobManager.start();
|
|
6257
6227
|
}
|
|
6258
|
-
/**
|
|
6259
|
-
* stops the taskmanager
|
|
6260
|
-
*/
|
|
6261
6228
|
stop() {
|
|
6262
6229
|
this.cronJobManager.stop();
|
|
6263
6230
|
}
|