@cslug/queue 0.3.0 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cslug/queue",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Jobs and workers on Redis Streams, after-commit and durable dispatch, and the scheduler.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,9 +29,9 @@
29
29
  "bun": ">=1.3.14"
30
30
  },
31
31
  "peerDependencies": {
32
- "@cslug/core": "0.3.0",
33
- "@cslug/redis": "0.3.0",
34
- "@cslug/database": "0.3.0"
32
+ "@cslug/core": "0.4.0",
33
+ "@cslug/redis": "0.4.0",
34
+ "@cslug/database": "0.4.0"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@cslug/database": {
package/src/job.ts CHANGED
@@ -142,5 +142,15 @@ export function registerJob(job: JobClass): void {
142
142
 
143
143
  export const findJob = (name: string): JobClass | undefined => registry.get(name)
144
144
 
145
+ /** The registered jobs as `cslug describe jobs` shows them (payload as JSON Schema when the job has `Job.schema`). */
146
+ export const describeJobs = () =>
147
+ [...registry.values()].map((job) => {
148
+ const { backoff, ...settings } = settingsOf(job)
149
+ const schema: unknown = Reflect.get(job, 'payloadSchema')
150
+ const toJson: unknown = schema && Reflect.get(schema, 'toJSONSchema')
151
+ const payload = typeof toJson === 'function' ? { payload: toJson.call(schema) } : {}
152
+ return { name: jobName(job), ...settings, backoff: typeof backoff === 'function' ? 'custom' : backoff, ...payload }
153
+ })
154
+
145
155
  export const isJobClass = (value: unknown): value is JobClass =>
146
156
  typeof value === 'function' && value.prototype instanceof Job && !Object.is(value, Job)
package/src/provider.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { Clock, type Duration, EventBus, Logger, parseDuration, type RateLimit, ServiceProvider } from '@cslug/core'
2
2
  import { RedisConnections, RedisProvider } from '@cslug/redis'
3
3
  import { queueCommands } from './commands'
4
+ import { discoverJobs } from './discover'
5
+ import { describeJobs } from './job'
4
6
  import { QueuedListenerJob } from './listener-job'
5
7
  import { Outbox } from './outbox'
6
8
  import { Queue } from './queue'
@@ -65,6 +67,10 @@ export class QueueProvider extends ServiceProvider {
65
67
 
66
68
  register() {
67
69
  this.commands(queueCommands)
70
+ this.describe('jobs', async () => {
71
+ await discoverJobs(this.app)
72
+ return describeJobs()
73
+ })
68
74
  const config = this.config
69
75
  this.app.singleton(
70
76
  RedisQueue,
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
3
  import { arg, Command, CslugError, flag, Logger, ServiceProvider } from '@cslug/core'
4
+ import { jobName } from './job'
4
5
  import { QueueProvider } from './provider'
5
6
  import { RedisQueue } from './redis-queue'
6
7
  import { buildSchedule, type ScheduleDefinition } from './schedule'
@@ -15,6 +16,15 @@ export class ScheduleProvider extends ServiceProvider {
15
16
 
16
17
  register() {
17
18
  this.commands(scheduleCommands)
19
+ this.describe('schedules', () =>
20
+ this.app.resolve(Scheduler).entries.map((e) => ({
21
+ name: e.name,
22
+ when: e.description,
23
+ ...(e.tz ? { timezone: e.tz } : {}),
24
+ ...(e.job ? { job: jobName(e.job) } : {}),
25
+ overlap: e.overlap,
26
+ })),
27
+ )
18
28
  this.app.singleton(
19
29
  Scheduler,
20
30
  (c) =>