@rvoh/psychic-workers 0.2.1

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.
Files changed (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/src/background/BaseBackgroundedModel.js +50 -0
  4. package/dist/cjs/src/background/BaseBackgroundedService.js +40 -0
  5. package/dist/cjs/src/background/BaseScheduledService.js +31 -0
  6. package/dist/cjs/src/background/index.js +529 -0
  7. package/dist/cjs/src/background/types.js +2 -0
  8. package/dist/cjs/src/error/background/NoQueueForSpecifiedQueueName.js +15 -0
  9. package/dist/cjs/src/error/background/NoQueueForSpecifiedWorkstream.js +15 -0
  10. package/dist/cjs/src/helpers/EnvInternal.js +5 -0
  11. package/dist/cjs/src/index.js +19 -0
  12. package/dist/cjs/src/psychic-application-workers/cache.js +17 -0
  13. package/dist/cjs/src/psychic-application-workers/index.js +77 -0
  14. package/dist/esm/src/background/BaseBackgroundedModel.js +47 -0
  15. package/dist/esm/src/background/BaseBackgroundedService.js +37 -0
  16. package/dist/esm/src/background/BaseScheduledService.js +28 -0
  17. package/dist/esm/src/background/index.js +524 -0
  18. package/dist/esm/src/background/types.js +1 -0
  19. package/dist/esm/src/error/background/NoQueueForSpecifiedQueueName.js +12 -0
  20. package/dist/esm/src/error/background/NoQueueForSpecifiedWorkstream.js +12 -0
  21. package/dist/esm/src/helpers/EnvInternal.js +3 -0
  22. package/dist/esm/src/index.js +7 -0
  23. package/dist/esm/src/psychic-application-workers/cache.js +12 -0
  24. package/dist/esm/src/psychic-application-workers/index.js +74 -0
  25. package/dist/types/src/background/BaseBackgroundedModel.d.ts +15 -0
  26. package/dist/types/src/background/BaseBackgroundedService.d.ts +17 -0
  27. package/dist/types/src/background/BaseScheduledService.d.ts +11 -0
  28. package/dist/types/src/background/index.d.ts +101 -0
  29. package/dist/types/src/background/types.d.ts +7 -0
  30. package/dist/types/src/error/background/NoQueueForSpecifiedQueueName.d.ts +5 -0
  31. package/dist/types/src/error/background/NoQueueForSpecifiedWorkstream.d.ts +5 -0
  32. package/dist/types/src/helpers/EnvInternal.d.ts +6 -0
  33. package/dist/types/src/index.d.ts +7 -0
  34. package/dist/types/src/psychic-application-workers/cache.d.ts +4 -0
  35. package/dist/types/src/psychic-application-workers/index.d.ts +200 -0
  36. package/package.json +74 -0
@@ -0,0 +1,15 @@
1
+ import { Dream } from '@rvoh/dream';
2
+ import { BackgroundJobConfig } from './index.js';
3
+ import { BackgroundableMethodArgs } from './BaseBackgroundedService.js';
4
+ import { FunctionPropertyNames } from './types.js';
5
+ export default class BaseBackgroundedModel extends Dream {
6
+ static get backgroundJobConfig(): BackgroundJobConfig<BaseBackgroundedModel>;
7
+ get backgroundJobConfig(): BackgroundJobConfig<BaseBackgroundedModel>;
8
+ static background<T, MethodName extends PsychicBackgroundedModelStaticMethods<T & typeof BaseBackgroundedModel>, MethodFunc extends T[MethodName & keyof T], MethodArgs extends BackgroundableMethodArgs<MethodFunc>>(this: T, methodName: MethodName, ...args: MethodArgs): Promise<void>;
9
+ static backgroundWithDelay<T, MethodName extends PsychicBackgroundedModelStaticMethods<T & typeof BaseBackgroundedModel>, MethodFunc extends T[MethodName & keyof T], MethodArgs extends BackgroundableMethodArgs<MethodFunc>>(this: T, delaySeconds: number, methodName: MethodName, ...args: MethodArgs): Promise<void>;
10
+ get psychicTypes(): any;
11
+ background<T, MethodName extends PsychicBackgroundedServiceInstanceMethods<T & BaseBackgroundedModel>, MethodFunc extends T[MethodName & keyof T], MethodArgs extends BackgroundableMethodArgs<MethodFunc>>(this: T, methodName: MethodName, ...args: MethodArgs): Promise<void>;
12
+ backgroundWithDelay<T, MethodName extends PsychicBackgroundedServiceInstanceMethods<T & BaseBackgroundedModel>, MethodFunc extends T[MethodName & keyof T], MethodArgs extends BackgroundableMethodArgs<MethodFunc>>(this: T, delaySeconds: number, methodName: MethodName, ...args: MethodArgs): Promise<void>;
13
+ }
14
+ export type PsychicBackgroundedModelStaticMethods<T extends typeof BaseBackgroundedModel> = Exclude<FunctionPropertyNames<Required<T>>, FunctionPropertyNames<typeof BaseBackgroundedModel>>;
15
+ export type PsychicBackgroundedServiceInstanceMethods<T extends BaseBackgroundedModel> = Exclude<FunctionPropertyNames<Required<T>>, FunctionPropertyNames<BaseBackgroundedModel>>;
@@ -0,0 +1,17 @@
1
+ import { Job } from 'bullmq';
2
+ import { BackgroundJobConfig } from './index.js';
3
+ import { FunctionPropertyNames } from './types.js';
4
+ export default class BaseBackgroundedService {
5
+ static get backgroundJobConfig(): BackgroundJobConfig<BaseBackgroundedService>;
6
+ static get globalName(): string;
7
+ static setGlobalName(globalName: string): void;
8
+ private static _globalName;
9
+ static background<T, MethodName extends PsychicBackgroundedServiceStaticMethods<T & typeof BaseBackgroundedService>, MethodFunc extends T[MethodName & keyof T], MethodArgs extends BackgroundableMethodArgs<MethodFunc>>(this: T, methodName: MethodName, ...args: MethodArgs): Promise<void>;
10
+ static backgroundWithDelay<T, MethodName extends PsychicBackgroundedServiceStaticMethods<T & typeof BaseBackgroundedService>, MethodFunc extends T[MethodName & keyof T], MethodArgs extends BackgroundableMethodArgs<MethodFunc>>(this: T, delaySeconds: number, methodName: MethodName, ...args: MethodArgs): Promise<void>;
11
+ get psychicTypes(): any;
12
+ }
13
+ export type PsychicBackgroundedServiceStaticMethods<T extends typeof BaseBackgroundedService> = Exclude<FunctionPropertyNames<Required<T>>, FunctionPropertyNames<typeof BaseBackgroundedService>>;
14
+ export type PsychicBackgroundedServiceInstanceMethods<T extends BaseBackgroundedService> = Exclude<FunctionPropertyNames<Required<T>>, FunctionPropertyNames<BaseBackgroundedService>>;
15
+ type OmitJobFromEndOfArguments<Original extends unknown[]> = Original extends [Job] ? Original extends [string] ? Original : [] : Original extends [...infer Rest, Job] ? Original extends [...unknown[], string] ? Original : Rest : Original;
16
+ export type BackgroundableMethodArgs<MethodFunc> = MethodFunc extends (...args: any) => any ? OmitJobFromEndOfArguments<Parameters<MethodFunc>> : never;
17
+ export {};
@@ -0,0 +1,11 @@
1
+ import { BackgroundJobConfig } from './index.js';
2
+ import { FunctionPropertyNames } from './types.js';
3
+ export default class BaseScheduledService {
4
+ static get backgroundJobConfig(): BackgroundJobConfig<BaseScheduledService>;
5
+ static get globalName(): string;
6
+ static setGlobalName(globalName: string): void;
7
+ private static _globalName;
8
+ static schedule<T, MethodName extends FunctionPropertyNames<Required<T>>, MethodFunc extends T[MethodName & keyof T], MethodArgs extends MethodFunc extends (...args: any) => any ? Parameters<MethodFunc> : never>(this: T, pattern: string, methodName: MethodName, ...args: MethodArgs): Promise<void>;
9
+ get psychicTypes(): any;
10
+ }
11
+ export type PsychicScheduledServiceStaticMethods<T extends typeof BaseScheduledService> = Exclude<FunctionPropertyNames<Required<T>>, FunctionPropertyNames<typeof BaseScheduledService>>;
@@ -0,0 +1,101 @@
1
+ import { Dream, IdType } from '@rvoh/dream';
2
+ import { Job, Queue, Worker } from 'bullmq';
3
+ import { PsychicBackgroundNativeBullMQOptions, PsychicBackgroundSimpleOptions } from '../psychic-application-workers/index.js';
4
+ import BaseBackgroundedService from './BaseBackgroundedService.js';
5
+ import BaseScheduledService from './BaseScheduledService.js';
6
+ import { Either } from './types.js';
7
+ type JobTypes = 'BackgroundJobQueueFunctionJob' | 'BackgroundJobQueueStaticJob' | 'BackgroundJobQueueModelInstanceJob';
8
+ export interface BackgroundJobData {
9
+ id?: IdType;
10
+ method?: string;
11
+ args: any;
12
+ filepath?: string;
13
+ importKey?: string;
14
+ globalName?: string;
15
+ }
16
+ export declare class Background {
17
+ static get defaultQueueName(): string;
18
+ static get Worker(): typeof Worker;
19
+ static get Queue(): typeof Queue;
20
+ /**
21
+ * Used when adding jobs to the default queue
22
+ */
23
+ private defaultQueue;
24
+ /**
25
+ * Used when adding jobs to the default transitional queue
26
+ */
27
+ private defaultTransitionalQueue;
28
+ /**
29
+ * Used when adding jobs to a named queue
30
+ */
31
+ private namedQueues;
32
+ private groupNames;
33
+ private workstreamNames;
34
+ /**
35
+ * Used when adding jobs to a named transitioanl queue
36
+ */
37
+ private namedTransitionalQueues;
38
+ private _workers;
39
+ private redisConnections;
40
+ connect({ activateWorkers, }?: {
41
+ activateWorkers?: boolean;
42
+ }): void;
43
+ get queues(): Queue[];
44
+ get workers(): Worker<any, any, string>[];
45
+ private shutdownAndExit;
46
+ shutdown(): Promise<void>;
47
+ closeAllRedisConnections(): Promise<void>;
48
+ private simpleConnect;
49
+ private nativeBullMQConnect;
50
+ work(): void;
51
+ staticMethod(ObjectClass: Record<'name', string>, method: string, { delaySeconds, globalName, args, jobConfig, }: {
52
+ globalName: string;
53
+ filepath?: string;
54
+ delaySeconds?: number;
55
+ importKey?: string;
56
+ args?: any[];
57
+ jobConfig?: BackgroundJobConfig<any>;
58
+ }): Promise<void>;
59
+ scheduledMethod(ObjectClass: Record<'name', string>, pattern: string, method: string, { globalName, args, jobConfig, }: {
60
+ globalName: string;
61
+ filepath?: string;
62
+ importKey?: string;
63
+ args?: any[];
64
+ jobConfig?: BackgroundJobConfig<any>;
65
+ }): Promise<void>;
66
+ private queueInstance;
67
+ modelInstanceMethod(modelInstance: Dream, method: string, { delaySeconds, args, jobConfig, }: {
68
+ delaySeconds?: number;
69
+ importKey?: string;
70
+ args?: any[];
71
+ jobConfig?: BackgroundJobConfig<any>;
72
+ }): Promise<void>;
73
+ _addToQueue(jobType: JobTypes, jobData: BackgroundJobData, { delaySeconds, jobConfig, priority, groupId, }: {
74
+ delaySeconds?: number;
75
+ jobConfig: BackgroundJobConfig<any>;
76
+ priority: BackgroundQueuePriority;
77
+ groupId?: string;
78
+ }): Promise<void>;
79
+ private jobConfigToPriority;
80
+ private jobConfigToGroupId;
81
+ private jobConfigToGroup;
82
+ private groupIdToGroupConfig;
83
+ private mapPriorityWordToPriorityNumber;
84
+ doWork(job: Job): Promise<void>;
85
+ }
86
+ declare const background: Background;
87
+ export default background;
88
+ export declare function stopBackgroundWorkers(): Promise<void>;
89
+ export type BackgroundQueuePriority = 'default' | 'urgent' | 'not_urgent' | 'last';
90
+ interface BaseBackgroundJobConfig {
91
+ priority?: BackgroundQueuePriority;
92
+ }
93
+ export interface WorkstreamBackgroundJobConfig<T extends BaseScheduledService | BaseBackgroundedService> extends BaseBackgroundJobConfig {
94
+ workstream?: T['psychicTypes']['workstreamNames'][number];
95
+ }
96
+ export interface QueueBackgroundJobConfig<T extends BaseScheduledService | BaseBackgroundedService, PsyTypes extends T['psychicTypes'] = T['psychicTypes'], QueueGroupMap = PsyTypes['queueGroupMap'], Queue extends keyof QueueGroupMap = keyof QueueGroupMap, Groups extends QueueGroupMap[Queue] = QueueGroupMap[Queue], GroupId = Groups[number & keyof Groups]> extends BaseBackgroundJobConfig {
97
+ groupId?: GroupId;
98
+ queue?: Queue;
99
+ }
100
+ export type BackgroundJobConfig<T extends BaseScheduledService | BaseBackgroundedService> = Either<WorkstreamBackgroundJobConfig<T>, QueueBackgroundJobConfig<T>>;
101
+ export type PsychicBackgroundOptions = (PsychicBackgroundSimpleOptions & Partial<Record<Exclude<keyof PsychicBackgroundNativeBullMQOptions, keyof PsychicBackgroundSimpleOptions>, never>>) | (PsychicBackgroundNativeBullMQOptions & Partial<Record<Exclude<keyof PsychicBackgroundSimpleOptions, keyof PsychicBackgroundNativeBullMQOptions>, never>>);
@@ -0,0 +1,7 @@
1
+ export type FunctionProperties<T> = {
2
+ [K in keyof T as T[K] extends (...args: any[]) => any ? K : never]: T[K];
3
+ };
4
+ export type FunctionPropertyNames<T> = keyof FunctionProperties<T> & string;
5
+ type Only<T, U> = T & Partial<Record<Exclude<keyof U, keyof T>, never>>;
6
+ export type Either<T, U> = Only<T, U> | Only<U, T>;
7
+ export {};
@@ -0,0 +1,5 @@
1
+ export default class NoQueueForSpecifiedQueueName extends Error {
2
+ private queue;
3
+ constructor(queue: string);
4
+ get message(): string;
5
+ }
@@ -0,0 +1,5 @@
1
+ export default class NoQueueForSpecifiedWorkstream extends Error {
2
+ private workstream;
3
+ constructor(workstream: string);
4
+ get message(): string;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { Env } from '@rvoh/dream';
2
+ declare const EnvInternal: Env<{
3
+ string: "NODE_ENV" | "PSYCHIC_CORE_DEVELOPMENT";
4
+ boolean: "DEBUG" | "PSYCHIC_CORE_DEVELOPMENT" | "REALLY_TEST_BACKGROUND_QUEUE";
5
+ }, "NODE_ENV" | "PSYCHIC_CORE_DEVELOPMENT", never, "PSYCHIC_CORE_DEVELOPMENT" | "DEBUG" | "REALLY_TEST_BACKGROUND_QUEUE">;
6
+ export default EnvInternal;
@@ -0,0 +1,7 @@
1
+ export { default as background, Background, type BackgroundJobConfig, type BackgroundQueuePriority, stopBackgroundWorkers, } from './background/index.js';
2
+ export { default as BaseBackgroundedModel } from './background/BaseBackgroundedModel.js';
3
+ export { default as BaseBackgroundedService } from './background/BaseBackgroundedService.js';
4
+ export { default as BaseScheduledService } from './background/BaseScheduledService.js';
5
+ export { type BullMQNativeWorkerOptions, default as PsychicApplicationWorkers, type PsychicBackgroundNativeBullMQOptions, type PsychicBackgroundSimpleOptions, type PsychicBackgroundWorkstreamOptions, type QueueOptionsWithConnectionInstance, type RedisOrRedisClusterConnection, type TransitionalPsychicBackgroundSimpleOptions, } from './psychic-application-workers/index.js';
6
+ export { default as NoQueueForSpecifiedQueueName } from './error/background/NoQueueForSpecifiedQueueName.js';
7
+ export { default as NoQueueForSpecifiedWorkstream } from './error/background/NoQueueForSpecifiedWorkstream.js';
@@ -0,0 +1,4 @@
1
+ import PsychicApplicationWorkers from './index.js';
2
+ export declare function cachePsychicWorkersApplication(psychicWorkersApp: PsychicApplicationWorkers): void;
3
+ export declare function getCachedPsychicWorkersApplication(): PsychicApplicationWorkers | undefined;
4
+ export declare function getCachedPsychicWorkersApplicationOrFail(): PsychicApplicationWorkers;
@@ -0,0 +1,200 @@
1
+ import { PsychicApplication } from '@rvoh/psychic';
2
+ import { QueueOptions, WorkerOptions } from 'bullmq';
3
+ import { Cluster, Redis } from 'ioredis';
4
+ import { PsychicBackgroundOptions } from '../background/index.js';
5
+ export default class PsychicApplicationWorkers {
6
+ static init(psychicApp: PsychicApplication, cb: (app: PsychicApplicationWorkers) => void | Promise<void>): Promise<PsychicApplicationWorkers>;
7
+ /**
8
+ * Returns the cached psychic application if it has been set.
9
+ * If it has not been set, an exception is raised.
10
+ *
11
+ * The psychic application can be set by calling PsychicApplication#init
12
+ */
13
+ static getOrFail(): PsychicApplicationWorkers;
14
+ psychicApp: PsychicApplication;
15
+ constructor(psychicApp: PsychicApplication);
16
+ /**
17
+ * Returns the background options provided by the user
18
+ */
19
+ get backgroundOptions(): PsychicBackgroundOptions;
20
+ private _backgroundOptions;
21
+ private _hooks;
22
+ get hooks(): PsychicWorkersApplicationHooks;
23
+ on<T extends PsychicWorkersHookEventType>(hookEventType: T, cb: T extends 'workers:shutdown' ? () => void | Promise<void> : never): void;
24
+ set<Opt extends PsychicWorkersApplicationOption>(option: Opt, value: unknown): void;
25
+ }
26
+ export interface PsychicWorkersTypeSync {
27
+ workstreamNames: string[];
28
+ queueGroupMap: Record<string, string[]>;
29
+ }
30
+ export type PsychicWorkersApplicationOption = 'background';
31
+ export type PsychicWorkersHookEventType = 'workers:shutdown';
32
+ export interface PsychicWorkersApplicationHooks {
33
+ workerShutdown: (() => void | Promise<void>)[];
34
+ }
35
+ export interface BullMQNativeWorkerOptions extends WorkerOptions {
36
+ group?: {
37
+ id?: string;
38
+ maxSize?: number;
39
+ limit?: {
40
+ max?: number;
41
+ duration?: number;
42
+ };
43
+ concurrency?: number;
44
+ priority?: number;
45
+ };
46
+ concurrency?: number;
47
+ workerCount?: number;
48
+ }
49
+ export interface PsychicBackgroundNativeBullMQOptions extends PsychicBackgroundSharedOptions {
50
+ /**
51
+ * See https://docs.bullmq.io/guide/going-to-production for the different settings to use between
52
+ * queue and worker connections.
53
+ */
54
+ defaultQueueConnection?: RedisOrRedisClusterConnection;
55
+ defaultWorkerConnection?: RedisOrRedisClusterConnection;
56
+ nativeBullMQ: {
57
+ defaultQueueOptions?: QueueOptionsWithConnectionInstance;
58
+ /**
59
+ * named queues are useful for dispersing queues among nodes in a Redis cluster
60
+ * and for running queues on different Redis instances
61
+ */
62
+ namedQueueOptions?: Record<string, QueueOptionsWithConnectionInstance>;
63
+ /**
64
+ * Native BullMQ options to provide to configure the default workers
65
+ * for psychic. By default, Psychic leverages a single-queue system, with
66
+ * many workers running off the queue. Each worker receives the
67
+ * same worker configuration, so this configuration is really
68
+ * only used to supply the number of default workers that you want.
69
+ */
70
+ defaultWorkerOptions?: BullMQNativeWorkerOptions;
71
+ /**
72
+ * The number of default workers to run against the default Psychic
73
+ * background queues.
74
+ *
75
+ * By default, Psychic leverages a single-queue system, with
76
+ * many workers running off a single queue. This number determines
77
+ * the number of those default workers to provide.
78
+ */
79
+ defaultWorkerCount?: number;
80
+ /**
81
+ * namedQueueWorkers are necessary to work off namedQueues
82
+ * With BullMQ Pro, namedQueueWorkers can be rate limited (useful
83
+ * for interacting with external APIs)
84
+ */
85
+ namedQueueWorkers?: Record<string, BullMQNativeWorkerOptions>;
86
+ };
87
+ }
88
+ interface PsychicBackgroundSharedOptions {
89
+ /**
90
+ * If using BullMQ, these can be omitted. However, if you are using
91
+ * BullMQ Pro, you will need to provide the Queue and Worker
92
+ * classes custom from them.
93
+ */
94
+ providers?: {
95
+ Queue: any;
96
+ Worker: any;
97
+ };
98
+ defaultBullMQQueueOptions?: Omit<QueueOptions, 'connection'>;
99
+ }
100
+ export type QueueOptionsWithConnectionInstance = Omit<QueueOptions, 'connection'> & {
101
+ /**
102
+ * See https://docs.bullmq.io/guide/going-to-production for the different settings to use between
103
+ * queue and worker connections.
104
+ */
105
+ queueConnection?: RedisOrRedisClusterConnection;
106
+ workerConnection?: RedisOrRedisClusterConnection;
107
+ };
108
+ export interface PsychicBackgroundSimpleOptions extends PsychicBackgroundSharedOptions {
109
+ /**
110
+ * See https://docs.bullmq.io/guide/going-to-production for the different settings to use between
111
+ * queue and worker connections.
112
+ */
113
+ defaultQueueConnection: RedisOrRedisClusterConnection;
114
+ /**
115
+ * defaultWorkerConnection is only optional when workers will not be activated (e.g. on the webserver)
116
+ */
117
+ defaultWorkerConnection?: RedisOrRedisClusterConnection;
118
+ /**
119
+ * Every Psychic application that leverages simple background jobs will have a default
120
+ * workstream. Set workerCount to set the number of workers that will work through the
121
+ * default queue
122
+ */
123
+ defaultWorkstream?: {
124
+ workerCount?: number;
125
+ concurrency?: number;
126
+ };
127
+ /**
128
+ * When running background jobs on BullMQ, each named workstream corresponds
129
+ * to a specific queue and workers created for a named workstream are given
130
+ * a groupId corresponding to the workstream name
131
+ *
132
+ * named workstreams are useful for dispersing queues among nodes in a Redis cluster
133
+ * and for running queues on different Redis instances
134
+ *
135
+ * With BullMQ Pro, named workstreams can be rate limited (useful
136
+ * for interacting with external APIs)
137
+ */
138
+ namedWorkstreams?: PsychicBackgroundWorkstreamOptions[];
139
+ /**
140
+ * When transitioning from one instance of Redis to another, we can set up transitionalWorkstreams
141
+ * so that jobs already added to the legacy Redis instance continue to be worked. Once all jobs
142
+ * from the legacy Redis have been run, this configuration may be removed.
143
+ */
144
+ transitionalWorkstreams?: TransitionalPsychicBackgroundSimpleOptions;
145
+ }
146
+ export interface PsychicBackgroundWorkstreamOptions {
147
+ /**
148
+ * This will be the name of the queue (and the group if using BullMQ Pro)
149
+ */
150
+ name: string;
151
+ /**
152
+ * The number of workers you want to run on this configuration
153
+ */
154
+ workerCount?: number;
155
+ concurrency?: number;
156
+ /**
157
+ * See https://docs.bullmq.io/bullmq-pro/groups/rate-limiting for documentation
158
+ * on rate limiting in BullMQ Pro (requires paid BullMQ Pro license)
159
+ */
160
+ rateLimit?: {
161
+ max?: number;
162
+ duration?: number;
163
+ };
164
+ /**
165
+ * Optional redis connection. If not provided, the default background redis connection will be used.
166
+ * See https://docs.bullmq.io/guide/going-to-production for the different settings to use between
167
+ * queue and worker connections.
168
+ */
169
+ queueConnection?: RedisOrRedisClusterConnection;
170
+ workerConnection?: RedisOrRedisClusterConnection;
171
+ }
172
+ export interface PsychicBackgroundWorkstreamOptions {
173
+ /**
174
+ * This will be the name of the queue (and the group if using BullMQ Pro)
175
+ */
176
+ name: string;
177
+ /**
178
+ * The number of workers you want to run on this configuration
179
+ */
180
+ workerCount?: number;
181
+ concurrency?: number;
182
+ /**
183
+ * See https://docs.bullmq.io/bullmq-pro/groups/rate-limiting for documentation
184
+ * on rate limiting in BullMQ Pro (requires paid BullMQ Pro license)
185
+ */
186
+ rateLimit?: {
187
+ max?: number;
188
+ duration?: number;
189
+ };
190
+ /**
191
+ * Optional redis connection. If not provided, the default background redis connection will be used.
192
+ * See https://docs.bullmq.io/guide/going-to-production for the different settings to use between
193
+ * queue and worker connections.
194
+ */
195
+ queueConnection?: RedisOrRedisClusterConnection;
196
+ workerConnection?: RedisOrRedisClusterConnection;
197
+ }
198
+ export type TransitionalPsychicBackgroundSimpleOptions = Omit<PsychicBackgroundSimpleOptions, 'providers' | 'defaultBullMQQueueOptions' | 'transitionalWorkstreams'>;
199
+ export type RedisOrRedisClusterConnection = Redis | Cluster;
200
+ export {};
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "type": "module",
3
+ "name": "@rvoh/psychic-workers",
4
+ "description": "Background job system for Psychic applications",
5
+ "version": "0.2.1",
6
+ "author": "RVOHealth",
7
+ "repository": "https://github.com/rvohealth/psychic-workers.git",
8
+ "license": "MIT",
9
+ "main": "./dist/cjs/src/index.js",
10
+ "module": "./dist/esm/src/index.js",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/types/src/index.d.ts",
15
+ "import": "./dist/esm/src/index.js",
16
+ "require": "./dist/cjs/src/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist/**/*"
21
+ ],
22
+ "scripts": {
23
+ "publish": "yarn npm publish",
24
+ "psy": "yarn psyts",
25
+ "psyjs": "node ./dist/test-app/src/cli/index.js",
26
+ "psyts": "node --experimental-specifier-resolution=node --import ./bin/esm.js ./test-app/src/cli/index.ts",
27
+ "build": "echo \"building cjs...\" && rm -rf dist && npx tsc -p ./tsconfig.cjs.build.json && echo \"building esm...\" && npx tsc -p ./tsconfig.esm.build.json",
28
+ "uspec": "vitest --config ./spec/unit/vite.config.ts",
29
+ "format": "yarn run prettier . --write",
30
+ "lint": "yarn run eslint --no-warn-ignored \"src/**/*.ts\" && yarn run prettier . --check",
31
+ "prepack": "yarn build",
32
+ "dev-worker": "NODE_ENV=development WORKER_COUNT=1 ts-node --transpile-only ./test-app/worker.ts"
33
+ },
34
+ "peerDependencies": {
35
+ "@rvoh/dream": "*",
36
+ "@rvoh/psychic": "*",
37
+ "bullmq": "*",
38
+ "ioredis": "*"
39
+ },
40
+ "devDependencies": {
41
+ "@eslint/js": "=9.0.0",
42
+ "@rvoh/dream": "^0.29.1",
43
+ "@rvoh/dream-spec-helpers": "^0.2.0",
44
+ "@rvoh/psychic": "^0.24.1",
45
+ "@rvoh/psychic-spec-helpers": "^0.3.0",
46
+ "@socket.io/redis-adapter": "^8.3.0",
47
+ "@socket.io/redis-emitter": "^5.1.0",
48
+ "@types/express": "^4",
49
+ "@types/luxon": "^3.4.2",
50
+ "@types/node": "^22.5.1",
51
+ "@types/pg": "^8",
52
+ "@types/supertest": "^6.0.2",
53
+ "bullmq": "^5.12.12",
54
+ "eslint": "^9.9.1",
55
+ "express": "^4.21.2",
56
+ "ioredis": "^5.4.1",
57
+ "kysely": "^0.27.5",
58
+ "kysely-codegen": "^0.17.0",
59
+ "luxon": "^3.5.0",
60
+ "luxon-jest-matchers": "^0.1.14",
61
+ "pg": "^8.13.1",
62
+ "prettier": "^3.3.3",
63
+ "socket.io": "^4.8.1",
64
+ "socket.io-adapter": "^2.5.5",
65
+ "supertest": "^7.0.0",
66
+ "ts-node": "^10.9.2",
67
+ "tslib": "^2.7.0",
68
+ "typedoc": "^0.26.6",
69
+ "typescript": "^5.5.4",
70
+ "typescript-eslint": "=7.18.0",
71
+ "vitest": "^3.0.8"
72
+ },
73
+ "packageManager": "yarn@4.4.1"
74
+ }