@pikku/queue-pg-boss 0.12.4 → 0.12.6

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 CHANGED
@@ -1,3 +1,29 @@
1
+ ## 0.12.6
2
+
3
+ ### Patch Changes
4
+
5
+ - 41ce2cb: Upgrade to TypeScript 6 and raise the minimum Node.js version to 22.
6
+
7
+ All packages now build against `typescript@^6.0.3` and declare `engines.node >= 22`. Internal tooling (`ts-json-schema-generator`, `zod-to-ts`) was bumped to TypeScript 6-compatible releases.
8
+
9
+ - Updated dependencies [41ce2cb]
10
+ - @pikku/core@0.12.44
11
+
12
+ ## 0.12.5
13
+
14
+ ### Patch Changes
15
+
16
+ - 05aba57: fix(scheduler): prune orphaned recurring-task schedules on start
17
+
18
+ When a scheduled task is removed from code, its pg-boss schedule row survived and
19
+ kept producing jobs into a queue with no registered worker — the jobs piled up as
20
+ 'created' forever and could flood the queue (thousands of stuck jobs). `start()`
21
+ now drops any `pikku-recurring-scheduled-task_*` schedule and queue that is no
22
+ longer registered, so task removals self-heal on the next boot.
23
+
24
+ - Updated dependencies [a8022e5]
25
+ - @pikku/core@0.12.43
26
+
1
27
  ## 0.12.4
2
28
 
3
29
  ### Patch Changes
@@ -1,6 +1,8 @@
1
1
  import { SchedulerService, parseDurationString } from '@pikku/core';
2
2
  import { pikkuState } from '@pikku/core/internal';
3
3
  import { runScheduledTask, getScheduledTasks } from '@pikku/core/scheduler';
4
+ /** Prefix for pg-boss queues/schedules backing recurring scheduled tasks. */
5
+ const RECURRING_TASK_PREFIX = 'pikku-recurring-scheduled-task_';
4
6
  /**
5
7
  * pg-boss scheduler service implementation
6
8
  * Uses pg-boss's schedule() API to store recurring jobs in PostgreSQL.
@@ -88,8 +90,10 @@ export class PgBossSchedulerService extends SchedulerService {
88
90
  async start() {
89
91
  const logger = pikkuState(null, 'package', 'singletonServices').logger;
90
92
  const scheduledTasks = getScheduledTasks();
93
+ const expectedCronNames = new Set();
91
94
  for (const [name, task] of scheduledTasks) {
92
- const cronName = `pikku-recurring-scheduled-task_${name.replace(/[^a-zA-Z0-9_\-.]/g, '_')}`;
95
+ const cronName = `${RECURRING_TASK_PREFIX}${name.replace(/[^a-zA-Z0-9_\-.]/g, '_')}`;
96
+ expectedCronNames.add(cronName);
93
97
  await this.pgBoss.createQueue(cronName);
94
98
  await this.pgBoss.schedule(cronName, task.schedule, {
95
99
  rpcName: name,
@@ -104,6 +108,25 @@ export class PgBossSchedulerService extends SchedulerService {
104
108
  }
105
109
  });
106
110
  }
111
+ // Prune orphaned schedules. A task removed from code leaves its pg-boss
112
+ // schedule behind; with no worker registered it keeps producing jobs that
113
+ // pile up as 'created' forever (this is how a removed task flooded a queue
114
+ // with thousands of stuck jobs). Drop any recurring schedule + queue that's
115
+ // no longer registered so task removals self-heal on the next boot.
116
+ try {
117
+ const existing = await this.pgBoss.getSchedules();
118
+ for (const schedule of existing) {
119
+ if (schedule.name.startsWith(RECURRING_TASK_PREFIX) &&
120
+ !expectedCronNames.has(schedule.name)) {
121
+ await this.pgBoss.unschedule(schedule.name);
122
+ await this.pgBoss.deleteQueue(schedule.name);
123
+ logger.warn(`Pruned orphaned scheduled task queue: ${schedule.name}`);
124
+ }
125
+ }
126
+ }
127
+ catch (err) {
128
+ logger.warn(`Failed to prune orphaned scheduled tasks: ${err instanceof Error ? err.message : String(err)}`);
129
+ }
107
130
  }
108
131
  /**
109
132
  * Stop recurring scheduled tasks by unscheduling them from pg-boss.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/queue-pg-boss",
3
- "version": "0.12.4",
3
+ "version": "0.12.6",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -15,13 +15,13 @@
15
15
  "prepublishOnly": "yarn build"
16
16
  },
17
17
  "peerDependencies": {
18
- "@pikku/core": "^0.12.38"
18
+ "@pikku/core": "^0.12.44"
19
19
  },
20
20
  "dependencies": {
21
21
  "pg-boss": "^12.14.0"
22
22
  },
23
23
  "devDependencies": {
24
- "typescript": "^5.9"
24
+ "typescript": "^6.0.3"
25
25
  },
26
26
  "exports": {
27
27
  ".": "./dist/index.js"
@@ -17,6 +17,9 @@ interface ScheduledJobData {
17
17
  session?: CoreUserSession
18
18
  }
19
19
 
20
+ /** Prefix for pg-boss queues/schedules backing recurring scheduled tasks. */
21
+ const RECURRING_TASK_PREFIX = 'pikku-recurring-scheduled-task_'
22
+
20
23
  /**
21
24
  * pg-boss scheduler service implementation
22
25
  * Uses pg-boss's schedule() API to store recurring jobs in PostgreSQL.
@@ -131,8 +134,10 @@ export class PgBossSchedulerService extends SchedulerService {
131
134
  const logger = pikkuState(null, 'package', 'singletonServices')!.logger
132
135
  const scheduledTasks = getScheduledTasks()
133
136
 
137
+ const expectedCronNames = new Set<string>()
134
138
  for (const [name, task] of scheduledTasks) {
135
- const cronName = `pikku-recurring-scheduled-task_${name.replace(/[^a-zA-Z0-9_\-.]/g, '_')}`
139
+ const cronName = `${RECURRING_TASK_PREFIX}${name.replace(/[^a-zA-Z0-9_\-.]/g, '_')}`
140
+ expectedCronNames.add(cronName)
136
141
  await this.pgBoss.createQueue(cronName)
137
142
  await this.pgBoss.schedule(cronName, task.schedule, {
138
143
  rpcName: name,
@@ -148,6 +153,29 @@ export class PgBossSchedulerService extends SchedulerService {
148
153
  }
149
154
  })
150
155
  }
156
+
157
+ // Prune orphaned schedules. A task removed from code leaves its pg-boss
158
+ // schedule behind; with no worker registered it keeps producing jobs that
159
+ // pile up as 'created' forever (this is how a removed task flooded a queue
160
+ // with thousands of stuck jobs). Drop any recurring schedule + queue that's
161
+ // no longer registered so task removals self-heal on the next boot.
162
+ try {
163
+ const existing = await this.pgBoss.getSchedules()
164
+ for (const schedule of existing) {
165
+ if (
166
+ schedule.name.startsWith(RECURRING_TASK_PREFIX) &&
167
+ !expectedCronNames.has(schedule.name)
168
+ ) {
169
+ await this.pgBoss.unschedule(schedule.name)
170
+ await this.pgBoss.deleteQueue(schedule.name)
171
+ logger.warn(`Pruned orphaned scheduled task queue: ${schedule.name}`)
172
+ }
173
+ }
174
+ } catch (err) {
175
+ logger.warn(
176
+ `Failed to prune orphaned scheduled tasks: ${err instanceof Error ? err.message : String(err)}`
177
+ )
178
+ }
151
179
  }
152
180
 
153
181
  /**
@@ -1 +1 @@
1
- {"root":["./src/index.ts","./src/pg-boss-queue-service.ts","./src/pg-boss-queue-worker.ts","./src/pg-boss-scheduler-service.ts","./src/pg-boss-service-factory.ts","./src/utils.ts"],"version":"5.9.3"}
1
+ {"root":["./src/index.ts","./src/pg-boss-queue-service.ts","./src/pg-boss-queue-worker.ts","./src/pg-boss-scheduler-service.ts","./src/pg-boss-service-factory.ts","./src/utils.ts"],"version":"6.0.3"}