@unchainedshop/core-worker 4.4.0 → 4.5.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.
@@ -107,6 +107,7 @@ export declare const configureWorkerModule: ({ db, options }: ModuleInput<Worker
107
107
  }) => Promise<boolean>;
108
108
  status: (work: Work) => WorkStatus;
109
109
  addWork({ type, input, priority, scheduled, originalWorkId, worker, retries, }: Pick<Work, "type" | "originalWorkId" | "worker"> & Pick<Partial<Work>, "scheduled" | "priority" | "input" | "retries">): Promise<Work>;
110
+ addWorkIfNotExists(workData: Pick<Work, "type"> & Pick<Partial<Work>, "scheduled" | "priority" | "input" | "retries">, existenceCheck: (work: Work) => boolean): Promise<Work | null>;
110
111
  rescheduleWork: (currentWork: Work, scheduled: Date) => Promise<mongodb.WithId<Work> | null>;
111
112
  allocateWork: ({ types, worker, }: {
112
113
  types: string[];
@@ -257,6 +257,16 @@ export const configureWorkerModule = async ({ db, options }) => {
257
257
  emit(WorkerEventTypes.ADDED, removePrivateFields(work));
258
258
  return work;
259
259
  },
260
+ async addWorkIfNotExists(workData, existenceCheck) {
261
+ const workItems = await WorkQueue.find(buildQuerySelector({
262
+ types: [workData.type],
263
+ status: [WorkStatus.NEW, WorkStatus.ALLOCATED],
264
+ })).toArray();
265
+ const existingWork = workItems.find(existenceCheck);
266
+ if (existingWork)
267
+ return null;
268
+ return this.addWork(workData);
269
+ },
260
270
  rescheduleWork: async (currentWork, scheduled) => {
261
271
  const work = await WorkQueue.findOneAndUpdate(generateDbFilterById(currentWork._id), {
262
272
  $set: {
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-worker",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "main": "lib/worker-index.js",
5
5
  "types": "lib/worker-index.d.ts",
6
6
  "type": "module",
7
+ "sideEffects": false,
7
8
  "scripts": {
8
9
  "clean": "tsc -b --clean",
9
10
  "build": "tsc -b",
@@ -33,8 +34,8 @@
33
34
  },
34
35
  "homepage": "https://github.com/unchainedshop/unchained#readme",
35
36
  "dependencies": {
36
- "@unchainedshop/logger": "^4.4.0",
37
- "@unchainedshop/utils": "^4.4.0"
37
+ "@unchainedshop/logger": "^4.5.0",
38
+ "@unchainedshop/utils": "^4.5.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/node": "^25.0.0",