@workglow/supabase 0.3.1 → 0.3.2
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/dist/job-queue/SupabaseJobStore.d.ts +2 -6
- package/dist/job-queue/SupabaseJobStore.d.ts.map +1 -1
- package/dist/job-queue/SupabaseMessageQueue.d.ts +1 -14
- package/dist/job-queue/SupabaseMessageQueue.d.ts.map +1 -1
- package/dist/job-queue/SupabaseQueueStorage.d.ts +12 -0
- package/dist/job-queue/SupabaseQueueStorage.d.ts.map +1 -1
- package/dist/job-queue/browser.js +35 -57
- package/dist/job-queue/browser.js.map +6 -6
- package/dist/job-queue/createSupabaseQueue.d.ts +0 -3
- package/dist/job-queue/createSupabaseQueue.d.ts.map +1 -1
- package/dist/job-queue/node.js +35 -57
- package/dist/job-queue/node.js.map +6 -6
- package/package.json +7 -7
package/dist/job-queue/node.js
CHANGED
|
@@ -122,21 +122,6 @@ class SupabaseQueueStorage {
|
|
|
122
122
|
throw tableError;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
const alterSqls = [
|
|
126
|
-
`ALTER TABLE ${this.tableName} ADD COLUMN IF NOT EXISTS abort_requested_at timestamp with time zone`,
|
|
127
|
-
`ALTER TABLE ${this.tableName} ADD COLUMN IF NOT EXISTS lease_expires_at timestamp with time zone`,
|
|
128
|
-
`ALTER TABLE ${this.tableName} RENAME COLUMN run_after TO visible_at`,
|
|
129
|
-
`ALTER TABLE ${this.tableName} RENAME COLUMN last_ran_at TO last_attempted_at`,
|
|
130
|
-
`ALTER TABLE ${this.tableName} RENAME COLUMN run_attempts TO attempts`,
|
|
131
|
-
`ALTER TABLE ${this.tableName} RENAME COLUMN max_retries TO max_attempts`,
|
|
132
|
-
`ALTER TABLE ${this.tableName} RENAME COLUMN worker_id TO lease_owner`
|
|
133
|
-
];
|
|
134
|
-
for (const sql of alterSqls) {
|
|
135
|
-
const { error } = await this.client.rpc("exec_sql", { query: sql });
|
|
136
|
-
if (error && error.code !== "42703") {
|
|
137
|
-
throw new Error(`Failed to rename column: ${error.message}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
125
|
const indexes = [
|
|
141
126
|
`CREATE INDEX IF NOT EXISTS job_fetcher${indexSuffix}_idx ON ${this.tableName} (${prefixIndexPrefix}id, status, visible_at)`,
|
|
142
127
|
`CREATE INDEX IF NOT EXISTS job_queue_fetcher${indexSuffix}_idx ON ${this.tableName} (${prefixIndexPrefix}queue, status, visible_at)`,
|
|
@@ -582,6 +567,27 @@ class SupabaseQueueStorage {
|
|
|
582
567
|
if (error)
|
|
583
568
|
throw error;
|
|
584
569
|
}
|
|
570
|
+
async markDisabled(id) {
|
|
571
|
+
const numericId = Number(id);
|
|
572
|
+
if (!Number.isFinite(numericId)) {
|
|
573
|
+
throw new Error(`Invalid job id: ${id}`);
|
|
574
|
+
}
|
|
575
|
+
const prefixConditions = this.buildPrefixWhereSql();
|
|
576
|
+
const validatedQueueName = this.validateSqlValue(this.queueName, "queueName");
|
|
577
|
+
const escapedQueueName = this.escapeSqlString(validatedQueueName);
|
|
578
|
+
const sql = `
|
|
579
|
+
UPDATE ${this.tableName}
|
|
580
|
+
SET status = 'DISABLED',
|
|
581
|
+
completed_at = COALESCE(completed_at, NOW() AT TIME ZONE 'UTC'),
|
|
582
|
+
lease_owner = NULL,
|
|
583
|
+
progress = 0,
|
|
584
|
+
progress_message = '',
|
|
585
|
+
progress_details = NULL
|
|
586
|
+
WHERE id = ${numericId} AND queue = '${escapedQueueName}'${prefixConditions}`;
|
|
587
|
+
const { error } = await this.client.rpc("exec_sql", { query: sql });
|
|
588
|
+
if (error)
|
|
589
|
+
throw error;
|
|
590
|
+
}
|
|
585
591
|
async deleteJobsByStatusAndAge(status, olderThanMs) {
|
|
586
592
|
const cutoffDate = new Date(Date.now() - olderThanMs).toISOString();
|
|
587
593
|
let query = this.client.from(this.tableName).delete().eq("queue", this.queueName).eq("status", status).not("completed_at", "is", null).lte("completed_at", cutoffDate);
|
|
@@ -959,24 +965,20 @@ class SupabaseRateLimiterStorage {
|
|
|
959
965
|
// src/job-queue/SupabaseMessageQueue.ts
|
|
960
966
|
class SupabaseClaim {
|
|
961
967
|
core;
|
|
962
|
-
pending;
|
|
963
968
|
id;
|
|
964
969
|
body;
|
|
965
970
|
attempts;
|
|
966
971
|
workerId;
|
|
967
|
-
constructor(core,
|
|
972
|
+
constructor(core, id, body, attempts, workerId) {
|
|
968
973
|
this.core = core;
|
|
969
|
-
this.pending = pending;
|
|
970
974
|
this.id = id;
|
|
971
975
|
this.body = body;
|
|
972
976
|
this.attempts = attempts;
|
|
973
977
|
this.workerId = workerId;
|
|
974
978
|
}
|
|
975
979
|
async ack(result) {
|
|
976
|
-
const buf = this.pending.get(this.id);
|
|
977
|
-
this.pending.delete(this.id);
|
|
978
980
|
const current = await this.core.get(this.id) ?? this.body;
|
|
979
|
-
const output = result !== undefined ? result :
|
|
981
|
+
const output = result !== undefined ? result : current.output ?? null;
|
|
980
982
|
await this.core.finalize(this.id, {
|
|
981
983
|
output,
|
|
982
984
|
error: null,
|
|
@@ -986,7 +988,6 @@ class SupabaseClaim {
|
|
|
986
988
|
});
|
|
987
989
|
}
|
|
988
990
|
async retry(opts) {
|
|
989
|
-
this.pending.delete(this.id);
|
|
990
991
|
const delay = opts?.delaySeconds ?? 0;
|
|
991
992
|
const current = await this.core.get(this.id) ?? this.body;
|
|
992
993
|
await this.core.complete({
|
|
@@ -1002,12 +1003,10 @@ class SupabaseClaim {
|
|
|
1002
1003
|
}
|
|
1003
1004
|
async fail(opts) {
|
|
1004
1005
|
opts?.permanent;
|
|
1005
|
-
const buf = this.pending.get(this.id);
|
|
1006
|
-
this.pending.delete(this.id);
|
|
1007
1006
|
const current = await this.core.get(this.id) ?? this.body;
|
|
1008
|
-
const error = opts?.error !== undefined ? opts.error :
|
|
1009
|
-
const errorCode = opts?.errorCode !== undefined ? opts.errorCode :
|
|
1010
|
-
const abortRequested = opts?.abortRequested
|
|
1007
|
+
const error = opts?.error !== undefined ? opts.error : current.error ?? null;
|
|
1008
|
+
const errorCode = opts?.errorCode !== undefined ? opts.errorCode : current.error_code ?? null;
|
|
1009
|
+
const abortRequested = opts?.abortRequested === true;
|
|
1011
1010
|
await this.core.finalize(this.id, {
|
|
1012
1011
|
error,
|
|
1013
1012
|
error_code: errorCode,
|
|
@@ -1020,7 +1019,6 @@ class SupabaseClaim {
|
|
|
1020
1019
|
await this.core.extendLease(this.id, this.workerId, ms);
|
|
1021
1020
|
}
|
|
1022
1021
|
async disable() {
|
|
1023
|
-
this.pending.delete(this.id);
|
|
1024
1022
|
const current = await this.core.get(this.id);
|
|
1025
1023
|
const completedAt = current?.completed_at ?? new Date().toISOString();
|
|
1026
1024
|
await this.core.finalize(this.id, {
|
|
@@ -1037,10 +1035,8 @@ class SupabaseClaim {
|
|
|
1037
1035
|
class SupabaseMessageQueue {
|
|
1038
1036
|
scope;
|
|
1039
1037
|
core;
|
|
1040
|
-
|
|
1041
|
-
constructor(core, pending) {
|
|
1038
|
+
constructor(core) {
|
|
1042
1039
|
this.core = core;
|
|
1043
|
-
this.pending = pending;
|
|
1044
1040
|
this.scope = core.scope;
|
|
1045
1041
|
}
|
|
1046
1042
|
async send(body, opts) {
|
|
@@ -1060,12 +1056,11 @@ class SupabaseMessageQueue {
|
|
|
1060
1056
|
const job = await this.core.next(opts.workerId, { leaseMs: opts.leaseMs });
|
|
1061
1057
|
if (!job)
|
|
1062
1058
|
break;
|
|
1063
|
-
claims.push(new SupabaseClaim(this.core,
|
|
1059
|
+
claims.push(new SupabaseClaim(this.core, job.id, job, job.attempts ?? 0, opts.workerId));
|
|
1064
1060
|
}
|
|
1065
1061
|
return claims;
|
|
1066
1062
|
}
|
|
1067
1063
|
async releaseClaim(id) {
|
|
1068
|
-
this.pending.delete(id);
|
|
1069
1064
|
await this.core.releaseClaim(id);
|
|
1070
1065
|
}
|
|
1071
1066
|
async migrate() {
|
|
@@ -1099,10 +1094,8 @@ function applySendOptions(body, opts) {
|
|
|
1099
1094
|
// src/job-queue/SupabaseJobStore.ts
|
|
1100
1095
|
class SupabaseJobStore {
|
|
1101
1096
|
core;
|
|
1102
|
-
|
|
1103
|
-
constructor(core, pending) {
|
|
1097
|
+
constructor(core) {
|
|
1104
1098
|
this.core = core;
|
|
1105
|
-
this.pending = pending;
|
|
1106
1099
|
}
|
|
1107
1100
|
get(id) {
|
|
1108
1101
|
return this.core.get(id);
|
|
@@ -1122,27 +1115,13 @@ class SupabaseJobStore {
|
|
|
1122
1115
|
async saveProgress(id, progress, message, details) {
|
|
1123
1116
|
await this.core.saveProgress(id, progress, message, details);
|
|
1124
1117
|
}
|
|
1125
|
-
async saveResult(id, output) {
|
|
1126
|
-
const buf = this.pending.get(id) ?? {};
|
|
1127
|
-
buf.output = output ?? null;
|
|
1128
|
-
this.pending.set(id, buf);
|
|
1129
|
-
}
|
|
1130
|
-
async saveError(id, error, errorCode, abortRequested) {
|
|
1131
|
-
const buf = this.pending.get(id) ?? {};
|
|
1132
|
-
buf.error = error;
|
|
1133
|
-
buf.errorCode = errorCode;
|
|
1134
|
-
buf.abortRequested = abortRequested;
|
|
1135
|
-
this.pending.set(id, buf);
|
|
1136
|
-
}
|
|
1137
1118
|
async deleteByStatusAndAge(status, olderThanMs) {
|
|
1138
1119
|
await this.core.deleteJobsByStatusAndAge(status, olderThanMs);
|
|
1139
1120
|
}
|
|
1140
1121
|
async delete(id) {
|
|
1141
|
-
this.pending.delete(id);
|
|
1142
1122
|
await this.core.delete(id);
|
|
1143
1123
|
}
|
|
1144
1124
|
async deleteAll() {
|
|
1145
|
-
this.pending.clear();
|
|
1146
1125
|
await this.core.deleteAll();
|
|
1147
1126
|
}
|
|
1148
1127
|
async abort(id) {
|
|
@@ -1168,13 +1147,14 @@ class SupabaseJobStore {
|
|
|
1168
1147
|
return this.core.getMany(ids);
|
|
1169
1148
|
}
|
|
1170
1149
|
async completeWithResult(id, result) {
|
|
1171
|
-
this.pending.delete(id);
|
|
1172
1150
|
await this.core.completeWithResult(id, result);
|
|
1173
1151
|
}
|
|
1174
1152
|
async failWithError(id, opts) {
|
|
1175
|
-
this.pending.delete(id);
|
|
1176
1153
|
await this.core.failWithError(id, opts);
|
|
1177
1154
|
}
|
|
1155
|
+
async markDisabled(id) {
|
|
1156
|
+
await this.core.markDisabled(id);
|
|
1157
|
+
}
|
|
1178
1158
|
async markEnqueueDeferred(id, opts) {
|
|
1179
1159
|
await this.core.finalize(id, {
|
|
1180
1160
|
visible_at: opts.visible_at.toISOString(),
|
|
@@ -1185,11 +1165,9 @@ class SupabaseJobStore {
|
|
|
1185
1165
|
// src/job-queue/createSupabaseQueue.ts
|
|
1186
1166
|
function createSupabaseQueue(queueName, client, opts) {
|
|
1187
1167
|
const core = new SupabaseQueueStorage(client, queueName, opts);
|
|
1188
|
-
const pending = new Map;
|
|
1189
1168
|
return {
|
|
1190
|
-
messageQueue: new SupabaseMessageQueue(core
|
|
1191
|
-
jobStore: new SupabaseJobStore(core
|
|
1192
|
-
core
|
|
1169
|
+
messageQueue: new SupabaseMessageQueue(core),
|
|
1170
|
+
jobStore: new SupabaseJobStore(core)
|
|
1193
1171
|
};
|
|
1194
1172
|
}
|
|
1195
1173
|
export {
|
|
@@ -1202,4 +1180,4 @@ export {
|
|
|
1202
1180
|
SUPABASE_QUEUE_STORAGE
|
|
1203
1181
|
};
|
|
1204
1182
|
|
|
1205
|
-
//# debugId=
|
|
1183
|
+
//# debugId=245CD3EE76DB8E7764756E2164756E21
|