@contractspec/lib.jobs 0.0.0-canary-20260113162409
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/LICENSE +21 -0
- package/README.md +126 -0
- package/dist/_virtual/rolldown_runtime.js +36 -0
- package/dist/contracts/index.d.ts +547 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +482 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/entities/index.d.ts +145 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +198 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/events.d.ts +388 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +353 -0
- package/dist/events.js.map +1 -0
- package/dist/handlers/gmail-sync-handler.d.ts +10 -0
- package/dist/handlers/gmail-sync-handler.d.ts.map +1 -0
- package/dist/handlers/gmail-sync-handler.js +10 -0
- package/dist/handlers/gmail-sync-handler.js.map +1 -0
- package/dist/handlers/index.d.ts +10 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +13 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/ping-job.d.ts +11 -0
- package/dist/handlers/ping-job.d.ts.map +1 -0
- package/dist/handlers/ping-job.js +14 -0
- package/dist/handlers/ping-job.js.map +1 -0
- package/dist/handlers/storage-document-handler.d.ts +13 -0
- package/dist/handlers/storage-document-handler.d.ts.map +1 -0
- package/dist/handlers/storage-document-handler.js +15 -0
- package/dist/handlers/storage-document-handler.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs.capability.d.ts +8 -0
- package/dist/jobs.capability.d.ts.map +1 -0
- package/dist/jobs.capability.js +33 -0
- package/dist/jobs.capability.js.map +1 -0
- package/dist/jobs.feature.d.ts +12 -0
- package/dist/jobs.feature.d.ts.map +1 -0
- package/dist/jobs.feature.js +110 -0
- package/dist/jobs.feature.js.map +1 -0
- package/dist/queue/gcp-cloud-tasks.d.ts +42 -0
- package/dist/queue/gcp-cloud-tasks.d.ts.map +1 -0
- package/dist/queue/gcp-cloud-tasks.js +61 -0
- package/dist/queue/gcp-cloud-tasks.js.map +1 -0
- package/dist/queue/gcp-pubsub.d.ts +26 -0
- package/dist/queue/gcp-pubsub.d.ts.map +1 -0
- package/dist/queue/gcp-pubsub.js +47 -0
- package/dist/queue/gcp-pubsub.js.map +1 -0
- package/dist/queue/index.d.ts +16 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/index.js +23 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/queue/memory-queue.d.ts +35 -0
- package/dist/queue/memory-queue.d.ts.map +1 -0
- package/dist/queue/memory-queue.js +140 -0
- package/dist/queue/memory-queue.js.map +1 -0
- package/dist/queue/register-defined-job.d.ts +8 -0
- package/dist/queue/register-defined-job.d.ts.map +1 -0
- package/dist/queue/register-defined-job.js +16 -0
- package/dist/queue/register-defined-job.js.map +1 -0
- package/dist/queue/scaleway-sqs-queue.d.ts +39 -0
- package/dist/queue/scaleway-sqs-queue.d.ts.map +1 -0
- package/dist/queue/scaleway-sqs-queue.js +175 -0
- package/dist/queue/scaleway-sqs-queue.js.map +1 -0
- package/dist/queue/types.d.ts +8 -0
- package/dist/queue/types.d.ts.map +1 -0
- package/dist/queue/types.js +12 -0
- package/dist/queue/types.js.map +1 -0
- package/dist/scheduler/index.d.ts +93 -0
- package/dist/scheduler/index.d.ts.map +1 -0
- package/dist/scheduler/index.js +146 -0
- package/dist/scheduler/index.js.map +1 -0
- package/package.json +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
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,126 @@
|
|
|
1
|
+
# @contractspec/lib.jobs
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Background jobs and scheduler module for ContractSpec applications.
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Provides a generic system for asynchronous and scheduled work. Supports multiple queue backends (memory, Redis, GCP Cloud Tasks) and cron-like scheduling for recurring jobs.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Job Queue**: Async job processing with retry policies
|
|
15
|
+
- **Scheduler**: Cron-like scheduling for recurring jobs
|
|
16
|
+
- **Multiple Backends**: Memory, Redis, GCP Cloud Tasks, GCP Pub/Sub
|
|
17
|
+
- **Type Safety**: Typed job definitions with Zod schemas
|
|
18
|
+
- **Dead Letter Queue**: Automatic handling of failed jobs
|
|
19
|
+
- **Entity Specs**: Prisma schema generation for job persistence
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun add @contractspec/lib.jobs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Define a Job Type
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { defineJobType } from '@contractspec/lib.jobs';
|
|
33
|
+
import * as z from "zod";
|
|
34
|
+
|
|
35
|
+
const SendEmailJob = defineJobType({
|
|
36
|
+
type: 'email.send',
|
|
37
|
+
version: '1.0.0',
|
|
38
|
+
payload: z.object({
|
|
39
|
+
to: z.string().email(),
|
|
40
|
+
subject: z.string(),
|
|
41
|
+
body: z.string(),
|
|
42
|
+
}),
|
|
43
|
+
options: {
|
|
44
|
+
maxRetries: 3,
|
|
45
|
+
backoffMs: 5000,
|
|
46
|
+
timeoutMs: 30000,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Create a Queue
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { MemoryJobQueue, RedisJobQueue } from '@contractspec/lib.jobs/queue';
|
|
55
|
+
|
|
56
|
+
// In-memory for development
|
|
57
|
+
const queue = new MemoryJobQueue();
|
|
58
|
+
|
|
59
|
+
// Redis for production
|
|
60
|
+
const queue = new RedisJobQueue({
|
|
61
|
+
redis: redisClient,
|
|
62
|
+
prefix: 'jobs:',
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Enqueue and Process Jobs
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// Enqueue
|
|
70
|
+
await queue.enqueue('email.send', {
|
|
71
|
+
to: 'user@example.com',
|
|
72
|
+
subject: 'Welcome!',
|
|
73
|
+
body: 'Thanks for signing up.',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Register handler
|
|
77
|
+
queue.register('email.send', async (job) => {
|
|
78
|
+
await sendEmail(job.payload);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Start processing
|
|
82
|
+
queue.start();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Schedule Recurring Jobs
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { JobScheduler } from '@contractspec/lib.jobs/scheduler';
|
|
89
|
+
|
|
90
|
+
const scheduler = new JobScheduler(queue);
|
|
91
|
+
|
|
92
|
+
// Run daily at midnight
|
|
93
|
+
scheduler.schedule('daily-cleanup', '0 0 * * *', async () => {
|
|
94
|
+
await cleanupOldRecords();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Run every 5 minutes
|
|
98
|
+
scheduler.schedule('sync-data', '*/5 * * * *', async () => {
|
|
99
|
+
await syncExternalData();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
scheduler.start();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Entity Specs (for schema generation)
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { jobsSchemaContribution } from '@contractspec/lib.jobs/entities';
|
|
109
|
+
|
|
110
|
+
// Use in schema composition
|
|
111
|
+
const config = {
|
|
112
|
+
modules: [jobsSchemaContribution],
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Events
|
|
117
|
+
|
|
118
|
+
| Event | Trigger |
|
|
119
|
+
|-------|---------|
|
|
120
|
+
| job.enqueued | Job added to queue |
|
|
121
|
+
| job.started | Job processing started |
|
|
122
|
+
| job.completed | Job finished successfully |
|
|
123
|
+
| job.failed | Job failed after retries |
|
|
124
|
+
| job.retrying | Job is being retried |
|
|
125
|
+
| scheduler.tick | Scheduler checked for due jobs |
|
|
126
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __exportAll = (all, symbols) => {
|
|
7
|
+
let target = {};
|
|
8
|
+
for (var name in all) {
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (symbols) {
|
|
15
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
22
|
+
key = keys[i];
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: ((k) => from[k]).bind(null, key),
|
|
26
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { __exportAll, __reExport };
|