@@ -13,7 +13,7 @@ A worker does the following:
13
13
14
14
1 . Dequeues jobs that match the worker's ` queue `
15
15
2 . Processes jobs until there are none left
16
- 2 . Listens for new jobs using Supabase's Realtime feature
16
+ 3 . Listens for new jobs using Supabase's Realtime feature
17
17
18
18
Timeouts, delayed retries, and scale are left to the developer.
19
19
@@ -35,6 +35,13 @@ Run the migration:
35
35
supabase migration up --local
36
36
```
37
37
38
+ Update your ` supabase/config.toml ` to include the ` supaworker ` schema:
39
+
40
+ ``` toml
41
+ [api ]
42
+ schemas = [" public" , " supaworker" ]
43
+ ```
44
+
38
45
Sync the schema to your Supabase project:
39
46
40
47
``` bash
@@ -73,35 +80,31 @@ Edit package.json to use ESM modules:
73
80
Basic javascript example:
74
81
75
82
``` js
76
- import { createSupaworker } from " supaworker-js" ;
83
+ import { createSupaworker } from ' supaworker-js' ;
77
84
78
85
const clientOptions = {
79
- supabase_url: process .env .SUPABASE_URL ?? " " ,
80
- supabase_service_role_key: process .env .SUPABASE_SERVICE_ROLE_KEY ?? " " ,
86
+ supabase_url: process .env .SUPABASE_URL ?? ' ' ,
87
+ supabase_service_role_key: process .env .SUPABASE_SERVICE_ROLE_KEY ?? ' ' ,
81
88
};
82
89
83
90
const workerOptions = {
84
- queue: " example" ,
91
+ queue: ' example' ,
85
92
};
86
93
87
- const { enqueue , worker } = createSupaworker (
88
- clientOptions,
89
- workerOptions,
90
- async (job ) => {
91
- console .log (job .payload .message );
92
- }
93
- );
94
+ const { enqueue , worker } = createSupaworker (clientOptions, workerOptions, async (job ) => {
95
+ console .log (job .payload .message );
96
+ });
94
97
95
98
await enqueue ([
96
99
{
97
- queue: " example" ,
100
+ queue: ' example' ,
98
101
payload: {
99
- message: " Hello, World!" ,
102
+ message: ' Hello, World!' ,
100
103
},
101
104
},
102
105
]);
103
106
104
- process .on (" SIGINT" , async () => {
107
+ process .on (' SIGINT' , async () => {
105
108
await worker .stop ();
106
109
process .exit ();
107
110
});
@@ -135,35 +138,35 @@ import {
135
138
createSupaworker ,
136
139
type SupaworkerClientOptions ,
137
140
type SupaworkerOptions ,
138
- } from " supaworker-js" ;
141
+ } from ' supaworker-js' ;
139
142
140
143
const clientOptions: SupaworkerClientOptions = {
141
- supabase_url: import .meta.env.SUPABASE_URL ?? " " ,
142
- supabase_service_role_key: import .meta.env.SUPABASE_SERVICE_ROLE_KEY ?? " " ,
144
+ supabase_url: import .meta.env.SUPABASE_URL ?? ' ' ,
145
+ supabase_service_role_key: import .meta.env.SUPABASE_SERVICE_ROLE_KEY ?? ' ' ,
143
146
};
144
147
145
148
const workerOptions: SupaworkerOptions = {
146
- queue: " example" ,
149
+ queue: ' example' ,
147
150
};
148
151
149
152
const { enqueue , worker } = createSupaworker< { message: string }> (
150
153
clientOptions,
151
154
workerOptions,
152
155
async (job ) => {
153
156
console .log (job .payload ! .message );
154
- }
157
+ },
155
158
);
156
159
157
160
await enqueue ([
158
161
{
159
- queue: " example" ,
162
+ queue: ' example' ,
160
163
payload: {
161
- message: " Hello, World!" ,
164
+ message: ' Hello, World!' ,
162
165
},
163
166
},
164
167
]);
165
168
166
- process .on (" SIGINT" , async () => {
169
+ process .on (' SIGINT' , async () => {
167
170
await worker .stop ();
168
171
process .exit ();
169
172
});
@@ -178,4 +181,4 @@ Run the worker:
178
181
SUPABASE_URL = " " \
179
182
SUPABASE_SERVICE_ROLE_KEY = " " \
180
183
bun run index .ts
181
- ` ` `
184
+ ` ` `
0 commit comments