@adminforth/background-jobs 1.2.1 → 1.2.3
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/index.js +7 -6
- package/index.ts +12 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { afLogger } from "adminforth";
|
|
|
12
12
|
import pLimit from 'p-limit';
|
|
13
13
|
import { Level } from 'level';
|
|
14
14
|
import fs from 'fs/promises';
|
|
15
|
-
export default class extends AdminForthPlugin {
|
|
15
|
+
export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
16
16
|
constructor(options) {
|
|
17
17
|
super(options, import.meta.url);
|
|
18
18
|
this.taskHandlers = {};
|
|
@@ -37,6 +37,7 @@ export default class extends AdminForthPlugin {
|
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
var _a, _b;
|
|
39
39
|
_super.modifyResourceConfig.call(this, adminforth, resourceConfig);
|
|
40
|
+
console.log('Modifying resource config for Background Jobs Plugin');
|
|
40
41
|
if (!((_b = (_a = adminforth.config.customization) === null || _a === void 0 ? void 0 : _a.globalInjections) === null || _b === void 0 ? void 0 : _b.header)) {
|
|
41
42
|
adminforth.config.customization.globalInjections.header = [];
|
|
42
43
|
}
|
|
@@ -123,13 +124,13 @@ export default class extends AdminForthPlugin {
|
|
|
123
124
|
return Promise.resolve(null);
|
|
124
125
|
});
|
|
125
126
|
}
|
|
126
|
-
registerTaskHandler(jobHandlerName, handler,
|
|
127
|
+
registerTaskHandler({ jobHandlerName, handler, parallelLimit = 3, }) {
|
|
127
128
|
//register the handler in a map with jobHandlerName as key and handler as value
|
|
128
129
|
this.taskHandlers[jobHandlerName] = handler;
|
|
129
|
-
this.jobParallelLimits[jobHandlerName] =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
this.jobParallelLimits[jobHandlerName] = parallelLimit;
|
|
131
|
+
}
|
|
132
|
+
registerTaskDetailsComponent({ jobHandlerName, component, }) {
|
|
133
|
+
this.jobCustomComponents[jobHandlerName] = component;
|
|
133
134
|
}
|
|
134
135
|
startNewJob(jobName, adminUser, tasks, jobHandlerName) {
|
|
135
136
|
return __awaiter(this, void 0, void 0, function* () {
|
package/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ type taskType = {
|
|
|
15
15
|
state: Record<string, any>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export default class
|
|
18
|
+
export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
19
19
|
options: PluginOptions;
|
|
20
20
|
private taskHandlers: Record<string, taskHandlerType> = {};
|
|
21
21
|
private jobCustomComponents: Record<string, AdminForthComponentDeclarationFull> = {};
|
|
@@ -39,7 +39,7 @@ export default class extends AdminForthPlugin {
|
|
|
39
39
|
|
|
40
40
|
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
41
41
|
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
42
|
-
|
|
42
|
+
console.log('Modifying resource config for Background Jobs Plugin');
|
|
43
43
|
if (!adminforth.config.customization?.globalInjections?.header) {
|
|
44
44
|
adminforth.config.customization.globalInjections.header = [];
|
|
45
45
|
}
|
|
@@ -127,18 +127,18 @@ export default class extends AdminForthPlugin {
|
|
|
127
127
|
return Promise.resolve(null);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
public registerTaskHandler(
|
|
131
|
-
|
|
132
|
-
handler: taskHandlerType,
|
|
133
|
-
customComponent?: AdminForthComponentDeclarationFull,
|
|
134
|
-
parrallelLimit: number = 3,
|
|
135
|
-
) {
|
|
130
|
+
public registerTaskHandler({ jobHandlerName, handler, parallelLimit = 3,
|
|
131
|
+
}:{jobHandlerName: string, handler: taskHandlerType, parallelLimit?: number}) {
|
|
136
132
|
//register the handler in a map with jobHandlerName as key and handler as value
|
|
137
133
|
this.taskHandlers[jobHandlerName] = handler;
|
|
138
|
-
this.jobParallelLimits[jobHandlerName] =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
this.jobParallelLimits[jobHandlerName] = parallelLimit;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public registerTaskDetailsComponent({
|
|
138
|
+
jobHandlerName,
|
|
139
|
+
component,
|
|
140
|
+
}:{jobHandlerName: string, component: AdminForthComponentDeclarationFull}) {
|
|
141
|
+
this.jobCustomComponents[jobHandlerName] = component;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
public async startNewJob(
|