From 6f69ac62e18188933eb27a4931e2beaa72a19d1a Mon Sep 17 00:00:00 2001 From: Gerald Baulig Date: Mon, 23 Sep 2024 15:13:25 +0200 Subject: [PATCH] fix(scs-jobs): user prototypes, export relevant types export RunWorkerFunc and DefaultExportFunc to be used by external-job impl. --- package-lock.json | 3 +-- packages/acs-client/src/utils.ts | 4 ++-- packages/scs-jobs/package.json | 5 ++--- packages/scs-jobs/src/index.ts | 26 +++++++++++++++++++++----- packages/scs-jobs/src/types.ts | 25 +++++++++++-------------- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 76956446..e1e79609 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31439,8 +31439,7 @@ "@restorecommerce/rc-grpc-clients": "^5.1.35", "bullmq": "^5.7.15", "lodash": "^4.17.21", - "redis": "^4.6.8", - "winston": "^3.11.0" + "redis": "^4.6.8" }, "devDependencies": { "npm-run-all": "^4.1.5" diff --git a/packages/acs-client/src/utils.ts b/packages/acs-client/src/utils.ts index 7d02862f..71e5dee8 100644 --- a/packages/acs-client/src/utils.ts +++ b/packages/acs-client/src/utils.ts @@ -108,12 +108,12 @@ const checkSubjectMatch = ( ).map( aa => aa.value ); - + logger.debug('Role scoped instances for matching entity', { id: user?.id, ruleRoleScopeEntityName, matchingRoleScopedInstance }); // validate HR scope root ID contains the role scope instances const hrScopeExist = user?.hierarchical_scopes?.some((hrScope) => matchingRoleScopedInstance.includes(hrScope.id)); if (!hrScopeExist) { - logger.info('Hierarchial scopes for matching role does not exist', { + logger.info('Hierarchial scopes for matching role does not exist', { role: ruleRoleValue, hrScopes: user?.hierarchical_scopes, instances: matchingRoleScopedInstance diff --git a/packages/scs-jobs/package.json b/packages/scs-jobs/package.json index 714746ed..356e670d 100644 --- a/packages/scs-jobs/package.json +++ b/packages/scs-jobs/package.json @@ -23,15 +23,14 @@ "@restorecommerce/rc-grpc-clients": "^5.1.35", "bullmq": "^5.7.15", "lodash": "^4.17.21", - "redis": "^4.6.8", - "winston": "^3.11.0" + "redis": "^4.6.8" }, "devDependencies": { "npm-run-all": "^4.1.5" }, "scripts": { "test": "true", - "lint": "eslint src --ext .ts", + "lint": "eslint src --ext .ts --fix", "mocha": "cross-env NODE_ENV=test mocha --full-trace --exit --timeout 30000", "test-debug": "true", "lcov-report": "nyc report --reporter=lcov", diff --git a/packages/scs-jobs/src/index.ts b/packages/scs-jobs/src/index.ts index 1dd2677b..4a6f7dad 100644 --- a/packages/scs-jobs/src/index.ts +++ b/packages/scs-jobs/src/index.ts @@ -1,11 +1,11 @@ -import type { FilterOpts, JobType } from './types.js'; +import type { FilterOpts, JobType, Data } from './types.js'; import { createClient as createRedisClient } from 'redis'; import type { Events } from '@restorecommerce/kafka-client'; -import type { Logger } from 'winston'; +import type { ServiceConfig } from '@restorecommerce/service-config'; +import type { Logger } from '@restorecommerce/logger'; import * as _ from 'lodash'; import type { Processor } from 'bullmq'; import { Worker } from 'bullmq'; -import type { Data } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/job.js'; export const marshallProtobufAny = (msg: any): any => { return { @@ -67,7 +67,14 @@ export const _filterQueuedJob = (job: T, logger: Logger): }; -export const runWorker = async (queue: string, concurrency: number, cfg: any, logger: Logger, events: Events, cb: Processor): Promise => { +export const runWorker = async ( + queue: string, + concurrency: number, + cfg: ServiceConfig, + logger: Logger, + events: Events, + cb: Processor +): Promise => { // Get a redis connection const redisConfig = cfg.get('redis'); // below config is used for bull queu options and it still uses db config @@ -175,4 +182,13 @@ export const runWorker = async (queue: string, concurrency: number, cfg: any, lo worker.run().catch(err => logger.error(`worker#${queue} run error`, err)); await worker.waitUntilReady(); return worker; -}; \ No newline at end of file +}; + +export type RunWorkerFunc = typeof runWorker; +export type DefaultExportFunc = ( + cfg: ServiceConfig, + logger: Logger, + events: Event, + runWorker: RunWorkerFunc, +) => Promise; +export * from './types.js'; \ No newline at end of file diff --git a/packages/scs-jobs/src/types.ts b/packages/scs-jobs/src/types.ts index 19b1657c..18ac1490 100644 --- a/packages/scs-jobs/src/types.ts +++ b/packages/scs-jobs/src/types.ts @@ -1,14 +1,16 @@ -import type { JobsOptions } from 'bullmq'; +import { type JobsOptions } from 'bullmq'; -import type { Data } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/job.js'; +import { + type Data, + JobOptions_Priority as Priority, + JobReadRequest_SortOrder as SortOrder, +} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/job.js'; -export enum Priority { - NORMAL = 100, - LOW = 1000, - MEDIUM = 50, - HIGH = 25, - CRITICAL = 1, -} +export { + Data, + Priority, + SortOrder +}; export interface FilterOpts { id?: number | string; @@ -43,8 +45,3 @@ export interface NewJob { data: Data; id?: string; // mapped to jobId of bull } - -export enum SortOrder { - ASCENDING = 'ASCENDING', - DESCENDING = 'DESCENDING', -}