Skip to content

Commit

Permalink
fix(scs-jobs): user prototypes, export relevant types
Browse files Browse the repository at this point in the history
export RunWorkerFunc and DefaultExportFunc to be used by external-job impl.
  • Loading branch information
Gerald Baulig committed Sep 23, 2024
1 parent 9d1fbab commit 6f69ac6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/acs-client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions packages/scs-jobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 21 additions & 5 deletions packages/scs-jobs/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -67,7 +67,14 @@ export const _filterQueuedJob = <T extends FilterOpts>(job: T, logger: Logger):
};


export const runWorker = async (queue: string, concurrency: number, cfg: any, logger: Logger, events: Events, cb: Processor): Promise<Worker> => {
export const runWorker = async (
queue: string,
concurrency: number,
cfg: ServiceConfig,
logger: Logger,
events: Events,
cb: Processor
): Promise<Worker> => {
// Get a redis connection
const redisConfig = cfg.get('redis');
// below config is used for bull queu options and it still uses db config
Expand Down Expand Up @@ -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;
};
};

export type RunWorkerFunc = typeof runWorker;
export type DefaultExportFunc = (
cfg: ServiceConfig,
logger: Logger,
events: Event,
runWorker: RunWorkerFunc,
) => Promise<void>;
export * from './types.js';
25 changes: 11 additions & 14 deletions packages/scs-jobs/src/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,8 +45,3 @@ export interface NewJob {
data: Data;
id?: string; // mapped to jobId of bull
}

export enum SortOrder {
ASCENDING = 'ASCENDING',
DESCENDING = 'DESCENDING',
}

0 comments on commit 6f69ac6

Please sign in to comment.