@pikku/queue-bullmq 0.12.5 → 0.12.7
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/CHANGELOG.md +118 -0
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/bull-queue-service.d.ts +4 -3
- package/dist/bull-queue-service.js +5 -10
- package/dist/bull-queue-worker.js +3 -2
- package/dist/bull-scheduler-service.d.ts +5 -4
- package/dist/bull-scheduler-service.js +13 -15
- package/dist/index.d.ts +2 -1
- package/package.json +6 -5
- package/run-tests.sh +0 -0
- package/src/bull-queue-service.test.ts +6 -3
- package/src/bull-queue-service.ts +7 -12
- package/src/bull-queue-worker.ts +2 -2
- package/src/bull-scheduler-service.ts +18 -20
- package/src/index.ts +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
+
## 0.12.7
|
|
2
|
+
|
|
3
|
+
### Patch Changes
|
|
4
|
+
|
|
5
|
+
- 266e3bc: One door per name: `@pikku/core/ecosystem/*` and the package root are gone
|
|
6
|
+
|
|
7
|
+
`@pikku/core` published every module twice. `ecosystem/http` re-exported
|
|
8
|
+
`./http`, `ecosystem/services` re-exported `./services`, and a name was
|
|
9
|
+
reachable through either — so every addition had to be made in two places, and a
|
|
10
|
+
consumer's import said nothing about what it actually used. The package root was
|
|
11
|
+
the same problem at a larger scale: a single barrel of 206 names that no bundler
|
|
12
|
+
could take apart, and the one specifier that revealed nothing at all.
|
|
13
|
+
|
|
14
|
+
Both are deleted. Every name now lives on the subpath that owns it, and every
|
|
15
|
+
import carries that subpath — `@pikku/core/http`, `@pikku/core/services`,
|
|
16
|
+
`@pikku/core/errors`, `@pikku/core/types`.
|
|
17
|
+
|
|
18
|
+
Deleting the facades meant the raw subpaths had to become a superset of them,
|
|
19
|
+
which they were not: the facade tree had accumulated 25 names with no raw home
|
|
20
|
+
and about 26 more filed under a different area than the module they came from.
|
|
21
|
+
Those names moved to the area that owns them, and three areas were published as
|
|
22
|
+
new entry points rather than left on a root that is going away — `./types` (the
|
|
23
|
+
shared type surface, the largest single destination), `./state` and
|
|
24
|
+
`./classification`.
|
|
25
|
+
|
|
26
|
+
`./classification` is one door onto one subject: what a value is and how it must
|
|
27
|
+
be handled. Its three halves would each have been an entry point — the brands
|
|
28
|
+
and manifest types, the stored-form helpers (`hashToken`, `unsafeAsSealed` and
|
|
29
|
+
friends), and `SecretValue` — split by whether a name happens to be a type or a
|
|
30
|
+
value, which is the same defect as the facades. The duration and versioned-id
|
|
31
|
+
helpers went to `./utils`, which already published, and `PikkuRequest` went to
|
|
32
|
+
`./function`: it is the transport-agnostic request base, not an HTTP one — HTTP
|
|
33
|
+
has `PikkuHTTPAbstractRequest`, and the only thing outside core that extends
|
|
34
|
+
`PikkuRequest` is Azure's timer request.
|
|
35
|
+
|
|
36
|
+
`./types` inherited the root barrel's habit before it inherited its contents, so
|
|
37
|
+
the names with an owner elsewhere were moved off it. The middleware types and the
|
|
38
|
+
five middleware factories — `pikkuMiddleware`, `pikkuMiddlewareFactory`,
|
|
39
|
+
`pikkuChannelMiddleware`, `pikkuChannelMiddlewareFactory` and
|
|
40
|
+
`pikkuAgentMiddleware`, runtime values on a types entry point — are now
|
|
41
|
+
`@pikku/core/middleware`; the function meta types are `@pikku/core/function`;
|
|
42
|
+
`SerializedError` is `@pikku/core/errors`; and the generic TypeScript helpers
|
|
43
|
+
(`MakeRequired`, `PickRequired`, `PickOptional`, `RequireAtLeastOne`,
|
|
44
|
+
`JSONPrimitive`, `JSONValue`) are `@pikku/core/utils`. What is left on `./types`
|
|
45
|
+
is the vocabulary the wirings share, which no single module owns.
|
|
46
|
+
|
|
47
|
+
`pikku` was itself a root barrel — `export * from '@pikku/core'` — and
|
|
48
|
+
now exports only the services it bundles.
|
|
49
|
+
|
|
50
|
+
One module survives at the old specifier, and only for the bootstrap:
|
|
51
|
+
`packages/cli` is generated by the _published_ CLI pinned in its `build.sh`, and
|
|
52
|
+
that CLI still writes a bare `@pikku/core` into the files it generates for the
|
|
53
|
+
CLI itself. `bootstrap-compat/root.ts` carries the eight types it names, a test
|
|
54
|
+
in core fails if that list grows, and it goes when the pin moves to a CLI
|
|
55
|
+
released from this branch. The adapter names the pinned CLI reaches for —
|
|
56
|
+
`pikkuState` and `CreateWireServices` — are rewritten to `@pikku/core/state` and
|
|
57
|
+
`@pikku/core/types` by the same `build.sh` patch pass, so no second shim is
|
|
58
|
+
needed for them.
|
|
59
|
+
|
|
60
|
+
A guard test keeps the root shut: it parses imports and rejects a bare
|
|
61
|
+
`@pikku/core` rather than grepping for it, because several tests hold a user's
|
|
62
|
+
file as a template literal, where `import … from '@pikku/core'` is fixture text
|
|
63
|
+
rather than an import this repo makes.
|
|
64
|
+
|
|
65
|
+
An agent scaffold a project generated under an older CLI is refreshed rather
|
|
66
|
+
than left to fail: `pikku all` already deleted one importing an entry point
|
|
67
|
+
`@pikku/core` no longer publishes, and the `#pikku` hub joins that list.
|
|
68
|
+
Without it a project that scaffolds the agent endpoint but
|
|
69
|
+
declares no agents keeps the old file forever — the generator that would rewrite
|
|
70
|
+
it only runs when agents exist, and the file being present is what stops it
|
|
71
|
+
being regenerated as missing.
|
|
72
|
+
|
|
73
|
+
`pikku new addon` also wrote a tsconfig `paths` map naming only the deleted hub.
|
|
74
|
+
An addon's `imports` map points into `dist`, so `paths` is what resolves
|
|
75
|
+
`#pikku/<leaf>` for the addon's own source build — it now names the two leaf
|
|
76
|
+
patterns, in both the addon and its test harness.
|
|
77
|
+
|
|
78
|
+
- 786dae5: Bump every dependency whose latest release is a major across the monorepo, and
|
|
79
|
+
port the code the majors broke: `cookie` 2's `parseCookie`/`stringifySetCookie`
|
|
80
|
+
API in `@pikku/core` and the three runtime HTTP adapters, and assistant-ui 0.15's
|
|
81
|
+
store client in `@pikku/assistant-ui`.
|
|
82
|
+
- 6eef0a0: Bump every dependency to its latest compatible minor/patch across the monorepo.
|
|
83
|
+
- Updated dependencies [7722ceb]
|
|
84
|
+
- Updated dependencies [375c1ff]
|
|
85
|
+
- Updated dependencies [02a70cd]
|
|
86
|
+
- Updated dependencies [aeef159]
|
|
87
|
+
- Updated dependencies [a281de6]
|
|
88
|
+
- Updated dependencies [266e3bc]
|
|
89
|
+
- Updated dependencies [02a70cd]
|
|
90
|
+
- Updated dependencies [786dae5]
|
|
91
|
+
- Updated dependencies [6eef0a0]
|
|
92
|
+
- Updated dependencies [3561d67]
|
|
93
|
+
- Updated dependencies [a91c433]
|
|
94
|
+
- Updated dependencies [02a70cd]
|
|
95
|
+
- Updated dependencies [9537f74]
|
|
96
|
+
- Updated dependencies [2b57ca8]
|
|
97
|
+
- Updated dependencies [266e3bc]
|
|
98
|
+
- Updated dependencies [9fce0f1]
|
|
99
|
+
- Updated dependencies [83683a0]
|
|
100
|
+
- Updated dependencies [456c88b]
|
|
101
|
+
- Updated dependencies [456c88b]
|
|
102
|
+
- Updated dependencies [c127273]
|
|
103
|
+
- @pikku/core@0.12.85
|
|
104
|
+
|
|
105
|
+
## 0.12.6
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- 6794681: Publish the ecosystem surface as per-area sub-barrels under `@pikku/core/ecosystem/*`, and point generated code, the CLI, the inspector and the runtime adapters at them.
|
|
110
|
+
|
|
111
|
+
348 names that only generated code, the toolchain or a runtime adapter ever imports now have a second home on `@pikku/core/ecosystem/<area>` — one sub-barrel per area, matching how core already publishes its entrypoints, so no single barrel grows without bound and a consumer only pulls in the area it uses.
|
|
112
|
+
|
|
113
|
+
This step is additive: every name is still exported from the entrypoint it was published from before, so nothing downstream breaks. Removing them from the app-facing barrels is a later change, and needs a release carrying `./ecosystem/*` first.
|
|
114
|
+
|
|
115
|
+
- Updated dependencies [7406bfe]
|
|
116
|
+
- Updated dependencies [6794681]
|
|
117
|
+
- @pikku/core@0.12.84
|
|
118
|
+
|
|
1
119
|
## 0.12.5
|
|
2
120
|
|
|
3
121
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 - present Yasser Fadl and Pikku contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @pikku/queue-bullmq
|
|
2
|
+
|
|
3
|
+
BullMQ queue, worker and scheduler services for Pikku. Backed by Redis, with
|
|
4
|
+
job results, retries and priorities.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @pikku/queue-bullmq
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { BullQueueService, BullQueueWorkers } from '@pikku/queue-bullmq'
|
|
16
|
+
|
|
17
|
+
const queue = new BullQueueService({ host: 'localhost', port: 6379 })
|
|
18
|
+
|
|
19
|
+
const workers = new BullQueueWorkers({ host: 'localhost', port: 6379 })
|
|
20
|
+
|
|
21
|
+
await workers.registerQueues()
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Use `BullSchedulerService` for cron wirings. For a Postgres-backed alternative
|
|
25
|
+
see `@pikku/queue-pg-boss`.
|
|
26
|
+
|
|
27
|
+
## Docs
|
|
28
|
+
|
|
29
|
+
https://pikku.dev/docs
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ConnectionOptions, JobsOptions } from 'bullmq';
|
|
2
2
|
import type Bull from 'bullmq';
|
|
3
|
-
import type {
|
|
3
|
+
import type { QueueJob, QueueService } from '@pikku/core/queue';
|
|
4
|
+
import type { JobOptions } from '@pikku/core/queue';
|
|
4
5
|
export declare const mapPikkuJobToBull: (options?: JobOptions) => JobsOptions;
|
|
5
6
|
/**
|
|
6
7
|
* Bull/Redis queue service implementation
|
|
@@ -10,8 +11,8 @@ export declare class BullQueueService implements QueueService {
|
|
|
10
11
|
private redisConnectionOptions;
|
|
11
12
|
readonly name = "bull";
|
|
12
13
|
readonly supportsResults = true;
|
|
13
|
-
protected queues: Map<string, Bull.Queue<any, any, string, any, any, string>>;
|
|
14
|
-
protected queueEvents: Map<string, Bull.QueueEvents
|
|
14
|
+
protected queues: Map<string, Bull.Queue<any, any, string, any, any, string, Bull.RedisQueueBackend>>;
|
|
15
|
+
protected queueEvents: Map<string, Bull.QueueEvents<any>>;
|
|
15
16
|
constructor(redisConnectionOptions?: ConnectionOptions);
|
|
16
17
|
/**
|
|
17
18
|
* Create a Bull queue with translated configuration
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Queue, QueueEvents
|
|
1
|
+
import { Queue, QueueEvents } from 'bullmq';
|
|
2
2
|
import { mapBullJobToQueueJob } from './utils.js';
|
|
3
3
|
export const mapPikkuJobToBull = (options) => {
|
|
4
4
|
const bullOptions = {};
|
|
@@ -30,14 +30,6 @@ export const mapPikkuJobToBull = (options) => {
|
|
|
30
30
|
}
|
|
31
31
|
return bullOptions;
|
|
32
32
|
};
|
|
33
|
-
class PikkuRedisConnection extends RedisConnection {
|
|
34
|
-
constructor(options) {
|
|
35
|
-
super(options);
|
|
36
|
-
this.on('error', (error) => {
|
|
37
|
-
console.error('Redis connection error:', error);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
33
|
/**
|
|
42
34
|
* Bull/Redis queue service implementation
|
|
43
35
|
* Supports job results, retries, and most queue features
|
|
@@ -58,7 +50,10 @@ export class BullQueueService {
|
|
|
58
50
|
if (this.queues.has(queueName)) {
|
|
59
51
|
return this.queues.get(queueName);
|
|
60
52
|
}
|
|
61
|
-
const queue = new Queue(queueName, config
|
|
53
|
+
const queue = new Queue(queueName, config);
|
|
54
|
+
queue.on('error', (error) => {
|
|
55
|
+
console.error('Redis connection error:', error);
|
|
56
|
+
});
|
|
62
57
|
await queue.waitUntilReady();
|
|
63
58
|
this.queues.set(queueName, queue);
|
|
64
59
|
if (!this.queueEvents.has(queueName)) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Worker } from 'bullmq';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { runQueueJob } from '@pikku/core/queue';
|
|
3
|
+
import { registerQueueWorkers, QueueJobFailedError, QueueJobDiscardedError, } from '@pikku/core/queue';
|
|
4
|
+
import { pikkuState } from '@pikku/core/state';
|
|
4
5
|
import { mapBullJobToQueueJob } from './utils.js';
|
|
5
6
|
export const mapPikkuWorkerToBull = (workerConfig) => {
|
|
6
7
|
const workerOptions = {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ConnectionOptions } from 'bullmq';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { SchedulerService } from '@pikku/core/services';
|
|
3
|
+
import type { CoreUserSession } from '@pikku/core/types';
|
|
4
|
+
import type { ScheduledTaskInfo, ScheduledTaskSummary } from '@pikku/core/services';
|
|
4
5
|
export declare class BullSchedulerService extends SchedulerService {
|
|
5
6
|
private redisConnectionOptions;
|
|
6
7
|
private queue;
|
|
7
8
|
private recurringQueue;
|
|
8
9
|
private recurringWorker?;
|
|
9
|
-
private
|
|
10
|
+
private jobSchedulerIds;
|
|
10
11
|
constructor(redisConnectionOptions: ConnectionOptions);
|
|
11
12
|
/**
|
|
12
13
|
* Initialize - wait for queue to be ready
|
|
@@ -39,7 +40,7 @@ export declare class BullSchedulerService extends SchedulerService {
|
|
|
39
40
|
*/
|
|
40
41
|
start(): Promise<void>;
|
|
41
42
|
/**
|
|
42
|
-
* Stop recurring scheduled tasks by removing
|
|
43
|
+
* Stop recurring scheduled tasks by removing their job schedulers.
|
|
43
44
|
*/
|
|
44
45
|
stop(): Promise<void>;
|
|
45
46
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Queue, Worker } from 'bullmq';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { runScheduledTask } from '@pikku/core/scheduler';
|
|
3
|
+
import { SchedulerService } from '@pikku/core/services';
|
|
4
|
+
import { parseDurationString } from '@pikku/core/utils';
|
|
5
|
+
import { pikkuState } from '@pikku/core/state';
|
|
6
|
+
import { getScheduledTasks } from '@pikku/core/scheduler';
|
|
5
7
|
const RECURRING_QUEUE_NAME = 'pikku-recurring-scheduled-task';
|
|
6
8
|
export class BullSchedulerService extends SchedulerService {
|
|
7
9
|
redisConnectionOptions;
|
|
8
10
|
queue;
|
|
9
11
|
recurringQueue;
|
|
10
12
|
recurringWorker;
|
|
11
|
-
|
|
13
|
+
jobSchedulerIds = [];
|
|
12
14
|
constructor(redisConnectionOptions) {
|
|
13
15
|
super();
|
|
14
16
|
this.redisConnectionOptions = redisConnectionOptions;
|
|
@@ -125,23 +127,19 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
125
127
|
logger.error(`Recurring task worker error: ${err}`);
|
|
126
128
|
});
|
|
127
129
|
for (const [name, task] of scheduledTasks) {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
if (job.repeatJobKey) {
|
|
133
|
-
this.repeatJobKeys.push(job.repeatJobKey);
|
|
134
|
-
}
|
|
130
|
+
const jobSchedulerId = `recurring:${name}`;
|
|
131
|
+
await this.recurringQueue.upsertJobScheduler(jobSchedulerId, { pattern: task.schedule }, { name, data: { rpcName: name } });
|
|
132
|
+
this.jobSchedulerIds.push(jobSchedulerId);
|
|
135
133
|
}
|
|
136
134
|
}
|
|
137
135
|
/**
|
|
138
|
-
* Stop recurring scheduled tasks by removing
|
|
136
|
+
* Stop recurring scheduled tasks by removing their job schedulers.
|
|
139
137
|
*/
|
|
140
138
|
async stop() {
|
|
141
|
-
for (const
|
|
142
|
-
await this.recurringQueue.
|
|
139
|
+
for (const id of this.jobSchedulerIds) {
|
|
140
|
+
await this.recurringQueue.removeJobScheduler(id);
|
|
143
141
|
}
|
|
144
|
-
this.
|
|
142
|
+
this.jobSchedulerIds = [];
|
|
145
143
|
if (this.recurringWorker) {
|
|
146
144
|
await this.recurringWorker.close();
|
|
147
145
|
this.recurringWorker = undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export { BullServiceFactory } from './bull-service-factory.js';
|
|
|
8
8
|
export { BullQueueService } from './bull-queue-service.js';
|
|
9
9
|
export { BullQueueWorkers } from './bull-queue-worker.js';
|
|
10
10
|
export { BullSchedulerService } from './bull-scheduler-service.js';
|
|
11
|
-
export type {
|
|
11
|
+
export type { QueueJob, QueueService } from '@pikku/core/queue';
|
|
12
|
+
export type { PikkuWorkerConfig, PikkuJobConfig, JobOptions, } from '@pikku/core/queue';
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/queue-bullmq",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
|
+
"description": "BullMQ queue, worker and scheduler services for Pikku",
|
|
4
5
|
"author": "yasser.fadl@gmail.com",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"module": "dist/index.js",
|
|
@@ -15,11 +16,11 @@
|
|
|
15
16
|
"prepublishOnly": "yarn build"
|
|
16
17
|
},
|
|
17
18
|
"peerDependencies": {
|
|
18
|
-
"@pikku/core": "^0.12.
|
|
19
|
+
"@pikku/core": "^0.12.85"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"bullmq": "^
|
|
22
|
-
"ioredis": "^
|
|
22
|
+
"bullmq": "^6.1.1",
|
|
23
|
+
"ioredis": "^6.0.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"typescript": "^6.0.3"
|
|
@@ -27,4 +28,4 @@
|
|
|
27
28
|
"exports": {
|
|
28
29
|
".": "./dist/index.js"
|
|
29
30
|
}
|
|
30
|
-
}
|
|
31
|
+
}
|
package/run-tests.sh
CHANGED
|
File without changes
|
|
@@ -13,9 +13,12 @@ describe('mapPikkuJobToBull — retry mapping', () => {
|
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
test("string backoff 'exponential' → { type: 'exponential' }", () => {
|
|
16
|
-
assert.deepEqual(
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
assert.deepEqual(
|
|
17
|
+
mapPikkuJobToBull({ attempts: 6, backoff: 'exponential' }).backoff,
|
|
18
|
+
{
|
|
19
|
+
type: 'exponential',
|
|
20
|
+
}
|
|
21
|
+
)
|
|
19
22
|
})
|
|
20
23
|
|
|
21
24
|
test('object backoff → { type, delay } (delay stays in ms)', () => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ConnectionOptions, JobsOptions } from 'bullmq'
|
|
2
2
|
import type Bull from 'bullmq'
|
|
3
|
-
import { Queue, QueueEvents
|
|
4
|
-
import type {
|
|
3
|
+
import { Queue, QueueEvents } from 'bullmq'
|
|
4
|
+
import type { QueueJob, QueueService } from '@pikku/core/queue'
|
|
5
|
+
import type { JobOptions } from '@pikku/core/queue'
|
|
5
6
|
import { mapBullJobToQueueJob } from './utils.js'
|
|
6
7
|
|
|
7
8
|
export const mapPikkuJobToBull = (options?: JobOptions): JobsOptions => {
|
|
@@ -43,15 +44,6 @@ export const mapPikkuJobToBull = (options?: JobOptions): JobsOptions => {
|
|
|
43
44
|
return bullOptions
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
class PikkuRedisConnection extends RedisConnection {
|
|
47
|
-
constructor(options: ConnectionOptions) {
|
|
48
|
-
super(options)
|
|
49
|
-
this.on('error', (error) => {
|
|
50
|
-
console.error('Redis connection error:', error)
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
47
|
/**
|
|
56
48
|
* Bull/Redis queue service implementation
|
|
57
49
|
* Supports job results, retries, and most queue features
|
|
@@ -75,7 +67,10 @@ export class BullQueueService implements QueueService {
|
|
|
75
67
|
return this.queues.get(queueName)!
|
|
76
68
|
}
|
|
77
69
|
|
|
78
|
-
const queue = new Queue(queueName, config
|
|
70
|
+
const queue = new Queue(queueName, config)
|
|
71
|
+
queue.on('error', (error) => {
|
|
72
|
+
console.error('Redis connection error:', error)
|
|
73
|
+
})
|
|
79
74
|
await queue.waitUntilReady()
|
|
80
75
|
|
|
81
76
|
this.queues.set(queueName, queue)
|
package/src/bull-queue-worker.ts
CHANGED
|
@@ -7,13 +7,13 @@ import type {
|
|
|
7
7
|
QueueConfigMapping,
|
|
8
8
|
ConfigValidationResult,
|
|
9
9
|
} from '@pikku/core/queue'
|
|
10
|
+
import { runQueueJob } from '@pikku/core/queue'
|
|
10
11
|
import {
|
|
11
12
|
registerQueueWorkers,
|
|
12
|
-
runQueueJob,
|
|
13
13
|
QueueJobFailedError,
|
|
14
14
|
QueueJobDiscardedError,
|
|
15
15
|
} from '@pikku/core/queue'
|
|
16
|
-
import { pikkuState } from '@pikku/core/
|
|
16
|
+
import { pikkuState } from '@pikku/core/state'
|
|
17
17
|
import { mapBullJobToQueueJob } from './utils.js'
|
|
18
18
|
|
|
19
19
|
export const mapPikkuWorkerToBull = (
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ConnectionOptions } from 'bullmq'
|
|
2
2
|
import { Queue, Worker } from 'bullmq'
|
|
3
|
+
import { runScheduledTask } from '@pikku/core/scheduler'
|
|
4
|
+
import { SchedulerService } from '@pikku/core/services'
|
|
5
|
+
import type { CoreUserSession } from '@pikku/core/types'
|
|
3
6
|
import type {
|
|
4
7
|
ScheduledTaskInfo,
|
|
5
8
|
ScheduledTaskSummary,
|
|
6
|
-
|
|
7
|
-
} from '@pikku/core'
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { runScheduledTask, getScheduledTasks } from '@pikku/core/scheduler'
|
|
9
|
+
} from '@pikku/core/services'
|
|
10
|
+
import { parseDurationString } from '@pikku/core/utils'
|
|
11
|
+
import { pikkuState } from '@pikku/core/state'
|
|
12
|
+
import { getScheduledTasks } from '@pikku/core/scheduler'
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Data stored in scheduled job
|
|
@@ -24,7 +26,7 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
24
26
|
private queue: Queue
|
|
25
27
|
private recurringQueue: Queue
|
|
26
28
|
private recurringWorker?: Worker
|
|
27
|
-
private
|
|
29
|
+
private jobSchedulerIds: string[] = []
|
|
28
30
|
|
|
29
31
|
constructor(private redisConnectionOptions: ConnectionOptions) {
|
|
30
32
|
super()
|
|
@@ -170,28 +172,24 @@ export class BullSchedulerService extends SchedulerService {
|
|
|
170
172
|
})
|
|
171
173
|
|
|
172
174
|
for (const [name, task] of scheduledTasks) {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{
|
|
177
|
-
|
|
178
|
-
jobId: `recurring:${name}`,
|
|
179
|
-
}
|
|
175
|
+
const jobSchedulerId = `recurring:${name}`
|
|
176
|
+
await this.recurringQueue.upsertJobScheduler(
|
|
177
|
+
jobSchedulerId,
|
|
178
|
+
{ pattern: task.schedule },
|
|
179
|
+
{ name, data: { rpcName: name } as ScheduledJobData }
|
|
180
180
|
)
|
|
181
|
-
|
|
182
|
-
this.repeatJobKeys.push(job.repeatJobKey)
|
|
183
|
-
}
|
|
181
|
+
this.jobSchedulerIds.push(jobSchedulerId)
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
/**
|
|
188
|
-
* Stop recurring scheduled tasks by removing
|
|
186
|
+
* Stop recurring scheduled tasks by removing their job schedulers.
|
|
189
187
|
*/
|
|
190
188
|
async stop(): Promise<void> {
|
|
191
|
-
for (const
|
|
192
|
-
await this.recurringQueue.
|
|
189
|
+
for (const id of this.jobSchedulerIds) {
|
|
190
|
+
await this.recurringQueue.removeJobScheduler(id)
|
|
193
191
|
}
|
|
194
|
-
this.
|
|
192
|
+
this.jobSchedulerIds = []
|
|
195
193
|
if (this.recurringWorker) {
|
|
196
194
|
await this.recurringWorker.close()
|
|
197
195
|
this.recurringWorker = undefined
|
package/src/index.ts
CHANGED
|
@@ -11,10 +11,9 @@ export { BullQueueWorkers } from './bull-queue-worker.js'
|
|
|
11
11
|
export { BullSchedulerService } from './bull-scheduler-service.js'
|
|
12
12
|
|
|
13
13
|
// Re-export core queue types for convenience
|
|
14
|
+
export type { QueueJob, QueueService } from '@pikku/core/queue'
|
|
14
15
|
export type {
|
|
15
|
-
QueueService,
|
|
16
16
|
PikkuWorkerConfig,
|
|
17
17
|
PikkuJobConfig,
|
|
18
|
-
QueueJob,
|
|
19
18
|
JobOptions,
|
|
20
19
|
} from '@pikku/core/queue'
|