@adminforth/background-jobs 1.5.0 → 1.6.0
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/build.log +2 -2
- package/custom/JobInfoPopup.vue +1 -1
- package/custom/StateToIcon.vue +19 -6
- package/dist/custom/JobInfoPopup.vue +1 -1
- package/dist/custom/StateToIcon.vue +19 -6
- package/dist/index.js +15 -2
- package/index.ts +18 -3
- package/package.json +2 -2
package/build.log
CHANGED
|
@@ -11,5 +11,5 @@ custom/StateToIcon.vue
|
|
|
11
11
|
custom/tsconfig.json
|
|
12
12
|
custom/utils.ts
|
|
13
13
|
|
|
14
|
-
sent
|
|
15
|
-
total size is 12,
|
|
14
|
+
sent 13,135 bytes received 134 bytes 26,538.00 bytes/sec
|
|
15
|
+
total size is 12,650 speedup is 0.95
|
package/custom/JobInfoPopup.vue
CHANGED
package/custom/StateToIcon.vue
CHANGED
|
@@ -1,40 +1,53 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<Tooltip v-if="job
|
|
2
|
+
<Tooltip v-if="job?.status === 'IN_PROGRESS' || status === 'IN_PROGRESS'">
|
|
3
3
|
<Spinner class="w-5 h-5 ml-2" />
|
|
4
4
|
<template #tooltip>
|
|
5
5
|
{{ t('In progress') }}
|
|
6
6
|
</template>
|
|
7
7
|
</Tooltip>
|
|
8
|
-
<Tooltip v-else-if="job
|
|
8
|
+
<Tooltip v-else-if="job?.status === 'DONE' || status === 'DONE'">
|
|
9
9
|
<IconCheckCircleOutline class="w-6 h-6 ml-2 text-green-500" />
|
|
10
10
|
<template #tooltip>
|
|
11
11
|
{{ t('Done') }}
|
|
12
12
|
</template>
|
|
13
13
|
</Tooltip>
|
|
14
|
-
<Tooltip v-else-if="job
|
|
14
|
+
<Tooltip v-else-if="job?.status === 'CANCELLED' || status === 'CANCELLED'">
|
|
15
15
|
<IconCloseCircleOutline class="w-6 h-6 ml-2 text-red-500" />
|
|
16
16
|
<template #tooltip>
|
|
17
17
|
{{ t('Cancelled') }}
|
|
18
18
|
</template>
|
|
19
19
|
</Tooltip>
|
|
20
|
-
<Tooltip v-else-if="job
|
|
20
|
+
<Tooltip v-else-if="job?.status === 'DONE_WITH_ERRORS' || status === 'DONE_WITH_ERRORS'">
|
|
21
21
|
<IconExclamationCircleOutline class="w-6 h-6 ml-2 text-yellow-500" />
|
|
22
22
|
<template #tooltip>
|
|
23
23
|
{{ t('Done with errors') }}
|
|
24
24
|
</template>
|
|
25
25
|
</Tooltip>
|
|
26
|
+
<Tooltip v-else-if="status === 'FAILED'">
|
|
27
|
+
<IconCloseCircleOutline class="w-6 h-6 ml-2 text-red-500" />
|
|
28
|
+
<template #tooltip>
|
|
29
|
+
{{ t('Failed') }}
|
|
30
|
+
</template>
|
|
31
|
+
</Tooltip>
|
|
32
|
+
<Tooltip v-else-if="status === 'SCHEDULED'">
|
|
33
|
+
<IconClockOutline class="w-6 h-6 ml-2 text-blue-500" />
|
|
34
|
+
<template #tooltip>
|
|
35
|
+
{{ t('Scheduled') }}
|
|
36
|
+
</template>
|
|
37
|
+
</Tooltip>
|
|
26
38
|
</template>
|
|
27
39
|
|
|
28
40
|
|
|
29
41
|
<script setup lang="ts">
|
|
30
42
|
import type { IJob } from './utils';
|
|
31
|
-
import { IconCheckCircleOutline, IconCloseCircleOutline, IconExclamationCircleOutline } from '@iconify-prerendered/vue-flowbite';
|
|
43
|
+
import { IconCheckCircleOutline, IconCloseCircleOutline, IconExclamationCircleOutline, IconClockOutline } from '@iconify-prerendered/vue-flowbite';
|
|
32
44
|
import { Spinner, Tooltip } from '@/afcl';
|
|
33
45
|
import { useI18n } from 'vue-i18n';
|
|
34
46
|
|
|
35
47
|
const { t } = useI18n();
|
|
36
48
|
|
|
37
49
|
const props = defineProps<{
|
|
38
|
-
job
|
|
50
|
+
job?: IJob;
|
|
51
|
+
status?: 'SCHEDULED' | 'IN_PROGRESS' | 'DONE' | 'FAILED' | 'CANCELLED' | 'DONE_WITH_ERRORS';
|
|
39
52
|
}>();
|
|
40
53
|
</script>
|
|
@@ -1,40 +1,53 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<Tooltip v-if="job
|
|
2
|
+
<Tooltip v-if="job?.status === 'IN_PROGRESS' || status === 'IN_PROGRESS'">
|
|
3
3
|
<Spinner class="w-5 h-5 ml-2" />
|
|
4
4
|
<template #tooltip>
|
|
5
5
|
{{ t('In progress') }}
|
|
6
6
|
</template>
|
|
7
7
|
</Tooltip>
|
|
8
|
-
<Tooltip v-else-if="job
|
|
8
|
+
<Tooltip v-else-if="job?.status === 'DONE' || status === 'DONE'">
|
|
9
9
|
<IconCheckCircleOutline class="w-6 h-6 ml-2 text-green-500" />
|
|
10
10
|
<template #tooltip>
|
|
11
11
|
{{ t('Done') }}
|
|
12
12
|
</template>
|
|
13
13
|
</Tooltip>
|
|
14
|
-
<Tooltip v-else-if="job
|
|
14
|
+
<Tooltip v-else-if="job?.status === 'CANCELLED' || status === 'CANCELLED'">
|
|
15
15
|
<IconCloseCircleOutline class="w-6 h-6 ml-2 text-red-500" />
|
|
16
16
|
<template #tooltip>
|
|
17
17
|
{{ t('Cancelled') }}
|
|
18
18
|
</template>
|
|
19
19
|
</Tooltip>
|
|
20
|
-
<Tooltip v-else-if="job
|
|
20
|
+
<Tooltip v-else-if="job?.status === 'DONE_WITH_ERRORS' || status === 'DONE_WITH_ERRORS'">
|
|
21
21
|
<IconExclamationCircleOutline class="w-6 h-6 ml-2 text-yellow-500" />
|
|
22
22
|
<template #tooltip>
|
|
23
23
|
{{ t('Done with errors') }}
|
|
24
24
|
</template>
|
|
25
25
|
</Tooltip>
|
|
26
|
+
<Tooltip v-else-if="status === 'FAILED'">
|
|
27
|
+
<IconCloseCircleOutline class="w-6 h-6 ml-2 text-red-500" />
|
|
28
|
+
<template #tooltip>
|
|
29
|
+
{{ t('Failed') }}
|
|
30
|
+
</template>
|
|
31
|
+
</Tooltip>
|
|
32
|
+
<Tooltip v-else-if="status === 'SCHEDULED'">
|
|
33
|
+
<IconClockOutline class="w-6 h-6 ml-2 text-blue-500" />
|
|
34
|
+
<template #tooltip>
|
|
35
|
+
{{ t('Scheduled') }}
|
|
36
|
+
</template>
|
|
37
|
+
</Tooltip>
|
|
26
38
|
</template>
|
|
27
39
|
|
|
28
40
|
|
|
29
41
|
<script setup lang="ts">
|
|
30
42
|
import type { IJob } from './utils';
|
|
31
|
-
import { IconCheckCircleOutline, IconCloseCircleOutline, IconExclamationCircleOutline } from '@iconify-prerendered/vue-flowbite';
|
|
43
|
+
import { IconCheckCircleOutline, IconCloseCircleOutline, IconExclamationCircleOutline, IconClockOutline } from '@iconify-prerendered/vue-flowbite';
|
|
32
44
|
import { Spinner, Tooltip } from '@/afcl';
|
|
33
45
|
import { useI18n } from 'vue-i18n';
|
|
34
46
|
|
|
35
47
|
const { t } = useI18n();
|
|
36
48
|
|
|
37
49
|
const props = defineProps<{
|
|
38
|
-
job
|
|
50
|
+
job?: IJob;
|
|
51
|
+
status?: 'SCHEDULED' | 'IN_PROGRESS' | 'DONE' | 'FAILED' | 'CANCELLED' | 'DONE_WITH_ERRORS';
|
|
39
52
|
}>();
|
|
40
53
|
</script>
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,6 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
var _a, _b;
|
|
41
41
|
_super.modifyResourceConfig.call(this, adminforth, resourceConfig);
|
|
42
|
-
console.log('Modifying resource config for Background Jobs Plugin');
|
|
43
42
|
if (!((_b = (_a = adminforth.config.customization) === null || _a === void 0 ? void 0 : _a.globalInjections) === null || _b === void 0 ? void 0 : _b.header)) {
|
|
44
43
|
adminforth.config.customization.globalInjections.header = [];
|
|
45
44
|
}
|
|
@@ -49,6 +48,12 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
49
48
|
pluginInstanceId: this.pluginInstanceId,
|
|
50
49
|
}
|
|
51
50
|
});
|
|
51
|
+
if (!this.adminforth.config.componentsToExplicitRegister) {
|
|
52
|
+
this.adminforth.config.componentsToExplicitRegister = [];
|
|
53
|
+
}
|
|
54
|
+
this.adminforth.config.componentsToExplicitRegister.push({
|
|
55
|
+
file: this.componentPath('StateToIcon.vue')
|
|
56
|
+
});
|
|
52
57
|
if (!this.resourceConfig.hooks) {
|
|
53
58
|
this.resourceConfig.hooks = {};
|
|
54
59
|
}
|
|
@@ -134,6 +139,12 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
134
139
|
return Promise.resolve(null);
|
|
135
140
|
});
|
|
136
141
|
}
|
|
142
|
+
getTotalTasksInLevelDb(levelDb) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const count = yield levelDb.get('_meta:count');
|
|
145
|
+
return count ? parseInt(count, 10) : 0;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
137
148
|
registerTaskHandler({ jobHandlerName, handler, parallelLimit = 3, }) {
|
|
138
149
|
//register the handler in a map with jobHandlerName as key and handler as value
|
|
139
150
|
this.taskHandlers[jobHandlerName] = handler;
|
|
@@ -179,6 +190,7 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
179
190
|
//create a level db instance for the job with name as jobId
|
|
180
191
|
const jobLevelDb = new Level(`${this.options.levelDbPath || './background-jobs-dbs/'}job_${jobId}`, { valueEncoding: 'json' });
|
|
181
192
|
this.levelDbInstances[jobId] = jobLevelDb;
|
|
193
|
+
yield jobLevelDb.put('_meta:count', `${tasks.length}`);
|
|
182
194
|
const limit2 = pLimit(parrallelLimit);
|
|
183
195
|
const createTaskRecordsPromises = tasks.map((task, index) => {
|
|
184
196
|
return limit2(() => this.createLevelDbTaskRecord(jobLevelDb, index.toString(), task.state));
|
|
@@ -495,7 +507,8 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
495
507
|
tasks.push(parsedTaskData);
|
|
496
508
|
taskIndex++;
|
|
497
509
|
}
|
|
498
|
-
|
|
510
|
+
const total = yield this.getTotalTasksInLevelDb(jobLevelDb);
|
|
511
|
+
return { ok: true, data: { tasks, total } };
|
|
499
512
|
})
|
|
500
513
|
});
|
|
501
514
|
}
|
package/index.ts
CHANGED
|
@@ -41,7 +41,6 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
41
41
|
|
|
42
42
|
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
43
43
|
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
44
|
-
console.log('Modifying resource config for Background Jobs Plugin');
|
|
45
44
|
if (!adminforth.config.customization?.globalInjections?.header) {
|
|
46
45
|
adminforth.config.customization.globalInjections.header = [];
|
|
47
46
|
}
|
|
@@ -52,6 +51,15 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
52
51
|
}
|
|
53
52
|
});
|
|
54
53
|
|
|
54
|
+
if (!this.adminforth.config.componentsToExplicitRegister) {
|
|
55
|
+
this.adminforth.config.componentsToExplicitRegister = [];
|
|
56
|
+
}
|
|
57
|
+
this.adminforth.config.componentsToExplicitRegister.push(
|
|
58
|
+
{
|
|
59
|
+
file: this.componentPath('StateToIcon.vue')
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
55
63
|
if (!this.resourceConfig.hooks) {
|
|
56
64
|
this.resourceConfig.hooks = {};
|
|
57
65
|
}
|
|
@@ -138,6 +146,11 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
138
146
|
}
|
|
139
147
|
return Promise.resolve(null);
|
|
140
148
|
}
|
|
149
|
+
|
|
150
|
+
private async getTotalTasksInLevelDb(levelDb: Level): Promise<number> {
|
|
151
|
+
const count = await levelDb.get('_meta:count');
|
|
152
|
+
return count ? parseInt(count, 10) : 0;
|
|
153
|
+
}
|
|
141
154
|
|
|
142
155
|
public registerTaskHandler({ jobHandlerName, handler, parallelLimit = 3,
|
|
143
156
|
}:{jobHandlerName: string, handler: taskHandlerType, parallelLimit?: number}) {
|
|
@@ -197,7 +210,7 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
197
210
|
//create a level db instance for the job with name as jobId
|
|
198
211
|
const jobLevelDb = new Level(`${this.options.levelDbPath || './background-jobs-dbs/'}job_${jobId}`, { valueEncoding: 'json' });
|
|
199
212
|
this.levelDbInstances[jobId] = jobLevelDb;
|
|
200
|
-
|
|
213
|
+
await jobLevelDb.put('_meta:count', `${tasks.length}`);
|
|
201
214
|
const limit2 = pLimit(parrallelLimit);
|
|
202
215
|
const createTaskRecordsPromises = tasks.map((task, index) => {
|
|
203
216
|
return limit2(() => this.createLevelDbTaskRecord(jobLevelDb, index.toString(), task.state));
|
|
@@ -526,7 +539,9 @@ export default class BackgroundJobsPlugin extends AdminForthPlugin {
|
|
|
526
539
|
tasks.push(parsedTaskData);
|
|
527
540
|
taskIndex++;
|
|
528
541
|
}
|
|
529
|
-
|
|
542
|
+
|
|
543
|
+
const total = await this.getTotalTasksInLevelDb(jobLevelDb);
|
|
544
|
+
return { ok: true, data: { tasks, total } };
|
|
530
545
|
}
|
|
531
546
|
});
|
|
532
547
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/background-jobs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@vueuse/core": "^14.2.1",
|
|
23
|
-
"adminforth": "
|
|
23
|
+
"adminforth": "^2.24.0",
|
|
24
24
|
"async-mutex": "^0.5.0",
|
|
25
25
|
"level": "^10.0.0",
|
|
26
26
|
"p-limit": "^7.3.0"
|