@owlmeans/queue 0.1.18-rc.4 → 0.1.18-rc.40
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/README.md +285 -8
- package/agent-meta/manifest.json +9 -2
- package/agent-meta/skills/queue/SKILL.md +241 -12
- package/agent-meta/skills/scheduled-jobs/SKILL.md +151 -0
- package/build/bridge.d.ts +30 -0
- package/build/bridge.d.ts.map +1 -0
- package/build/bridge.js +108 -0
- package/build/bridge.js.map +1 -0
- package/build/config.d.ts +50 -0
- package/build/config.d.ts.map +1 -0
- package/build/config.js +141 -0
- package/build/config.js.map +1 -0
- package/build/consts.d.ts +33 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +35 -0
- package/build/consts.js.map +1 -0
- package/build/errors.d.ts +68 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +103 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +10 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +10 -1
- package/build/index.js.map +1 -1
- package/build/protocol.d.ts +10 -0
- package/build/protocol.d.ts.map +1 -0
- package/build/protocol.js +56 -0
- package/build/protocol.js.map +1 -0
- package/build/route.d.ts +9 -0
- package/build/route.d.ts.map +1 -0
- package/build/route.js +31 -0
- package/build/route.js.map +1 -0
- package/build/transport.d.ts +15 -0
- package/build/transport.d.ts.map +1 -0
- package/build/transport.js +59 -0
- package/build/transport.js.map +1 -0
- package/build/types.d.ts +309 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/build/types.local.d.ts +3 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/build/utils.d.ts +4 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +4 -0
- package/build/utils.js.map +1 -0
- package/build/worker.d.ts +27 -0
- package/build/worker.d.ts.map +1 -0
- package/build/worker.js +59 -0
- package/build/worker.js.map +1 -0
- package/package.json +13 -3
- package/src/bridge.ts +126 -0
- package/src/config.ts +171 -0
- package/src/consts.ts +38 -0
- package/src/errors.ts +121 -0
- package/src/index.ts +10 -0
- package/src/protocol.ts +74 -0
- package/src/route.ts +40 -0
- package/src/transport.ts +77 -0
- package/src/types.local.ts +3 -0
- package/src/types.ts +323 -0
- package/src/utils.ts +5 -0
- package/src/worker.ts +73 -0
- package/tests/bridge.spec.ts +64 -0
- package/tests/config.spec.ts +66 -0
- package/tests/protocol.spec.ts +58 -0
- package/tests/schedule.spec.ts +100 -0
- package/tsconfig.json +1 -0
- package/build/.gitkeep +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, test, expect } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
assertSchedule, assertSchedules, declareQueue, declareSchedule, queueOf, schedulesOf
|
|
4
|
+
} from '../src/config.js'
|
|
5
|
+
import { ScheduleMisdeclared, UnknownJobName, UnknownQueue } from '../src/errors.js'
|
|
6
|
+
import type { Config, ScheduleDeclaration } from '../src/types.js'
|
|
7
|
+
|
|
8
|
+
const cfg = (): Config => declareQueue(
|
|
9
|
+
declareQueue({ ready: false, service: 'test', type: 'backend' } as unknown as Config,
|
|
10
|
+
'maintenance', ['reconcile', 'sweep']),
|
|
11
|
+
'work', ['story:code']
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
const nightly: ScheduleDeclaration = {
|
|
15
|
+
id: 'nightly-reconcile', queue: 'maintenance', name: 'reconcile', pattern: '17 3 * * *', tz: 'UTC',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const misdeclared = (schedule: Partial<ScheduleDeclaration>): () => void =>
|
|
19
|
+
() => assertSchedule(cfg(), { ...nightly, ...schedule } as ScheduleDeclaration)
|
|
20
|
+
|
|
21
|
+
describe('declaring schedules', () => {
|
|
22
|
+
test('a declaration is recorded and read back by its queue', () => {
|
|
23
|
+
const config = declareSchedule(cfg(), nightly)
|
|
24
|
+
|
|
25
|
+
expect(schedulesOf(config, 'maintenance')).toEqual([nightly])
|
|
26
|
+
expect(schedulesOf(config, 'work')).toEqual([])
|
|
27
|
+
expect(schedulesOf(config)).toHaveLength(1)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('re-declaring an id replaces rather than appends', () => {
|
|
31
|
+
let config = declareSchedule(cfg(), nightly)
|
|
32
|
+
config = declareSchedule(config, { ...nightly, pattern: '0 4 * * *' })
|
|
33
|
+
|
|
34
|
+
expect(schedulesOf(config)).toHaveLength(1)
|
|
35
|
+
expect(schedulesOf(config)[0].pattern).toBe('0 4 * * *')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A scheduled run of a name the queue does not accept would fail on every tick. Refusing at
|
|
40
|
+
* declaration turns that into one error at boot, and the refused schedule is not recorded.
|
|
41
|
+
*/
|
|
42
|
+
test('a schedule for an undeclared queue or job name is refused and not recorded', () => {
|
|
43
|
+
const config = cfg()
|
|
44
|
+
|
|
45
|
+
expect(() => declareSchedule(config, { ...nightly, queue: 'missing' })).toThrow(UnknownQueue)
|
|
46
|
+
expect(() => declareSchedule(config, { ...nightly, name: 'story:code' })).toThrow(UnknownJobName)
|
|
47
|
+
expect(schedulesOf(config)).toHaveLength(0)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('re-declaring the queue keeps its schedules', () => {
|
|
51
|
+
const config = declareQueue(declareSchedule(cfg(), nightly), 'maintenance', ['reconcile'])
|
|
52
|
+
|
|
53
|
+
expect(queueOf(config, 'maintenance').jobs).toEqual(['reconcile'])
|
|
54
|
+
expect(schedulesOf(config)).toEqual([nightly])
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('asserting a schedule', () => {
|
|
59
|
+
test('exactly one of every and pattern', () => {
|
|
60
|
+
expect(misdeclared({ every: 1_000 })).toThrow(/every-or-pattern/)
|
|
61
|
+
expect(misdeclared({ pattern: undefined, tz: undefined })).toThrow(/every-or-pattern/)
|
|
62
|
+
expect(misdeclared({ pattern: undefined, tz: undefined, every: 0 })).toThrow(/:every$/)
|
|
63
|
+
expect(misdeclared({ pattern: undefined, tz: undefined, every: 1.5 })).toThrow(ScheduleMisdeclared)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('tz and immediately belong to a pattern only', () => {
|
|
67
|
+
expect(misdeclared({ pattern: undefined, every: 1_000 })).toThrow(/:tz$/)
|
|
68
|
+
expect(misdeclared({ pattern: undefined, tz: undefined, every: 1_000, immediately: true }))
|
|
69
|
+
.toThrow(/:immediately$/)
|
|
70
|
+
expect(misdeclared({ immediately: true, startDate: new Date() })).toThrow(/immediately-start-date/)
|
|
71
|
+
expect(misdeclared({ immediately: true })).not.toThrow()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('the broker owns a scheduled run\'s id and delay', () => {
|
|
75
|
+
expect(misdeclared({ opts: { id: 'fixed' } as ScheduleDeclaration['opts'] })).toThrow(/opts-id/)
|
|
76
|
+
expect(misdeclared({ opts: { delay: 10 } as ScheduleDeclaration['opts'] })).toThrow(/opts-delay/)
|
|
77
|
+
expect(misdeclared({ opts: { attempts: 3 } })).not.toThrow()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('an empty id is refused', () => {
|
|
81
|
+
expect(misdeclared({ id: ' ' })).toThrow(ScheduleMisdeclared)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('asserting every schedule', () => {
|
|
86
|
+
test('two schedules under one id are refused', () => {
|
|
87
|
+
const config = declareSchedule(cfg(), nightly)
|
|
88
|
+
config.queue?.schedules?.push({ ...nightly, pattern: '0 5 * * *' })
|
|
89
|
+
|
|
90
|
+
expect(() => assertSchedules(config)).toThrow(/duplicate/)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
/** The configuration is plain data; a schedule written into it directly is checked too. */
|
|
94
|
+
test('a schedule written past declareSchedule is still checked', () => {
|
|
95
|
+
const config = declareSchedule(cfg(), nightly)
|
|
96
|
+
config.queue?.schedules?.push({ id: 'orphan', queue: 'maintenance', name: 'gone', every: 1_000 })
|
|
97
|
+
|
|
98
|
+
expect(() => assertSchedules(config)).toThrow(UnknownJobName)
|
|
99
|
+
})
|
|
100
|
+
})
|
package/tsconfig.json
CHANGED
package/build/.gitkeep
DELETED
|
File without changes
|