lonnymq 0.0.23 → 0.0.24
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/index.cjs +161 -110
- package/dist/index.d.ts +36 -10
- package/dist/index.js +161 -110
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,44 +1,49 @@
|
|
|
1
|
-
var{defineProperty:
|
|
2
|
-
SELECT 1 FROM ${
|
|
1
|
+
var{defineProperty:N,getOwnPropertyNames:P,getOwnPropertyDescriptor:Q}=Object,V=Object.prototype.hasOwnProperty;var M=new WeakMap,W=(e)=>{var t=M.get(e),a;if(t)return t;if(t=N({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")P(e).map((r)=>!V.call(t,r)&&N(t,r,{get:()=>e[r],enumerable:!(a=Q(e,r))||a.enumerable}));return M.set(e,t),t};var Y=(e,t)=>{for(var a in t)N(e,a,{get:t[a],enumerable:!0,configurable:!0,set:(r)=>t[a]=()=>r})};var le={};Y(le,{queueEventDecode:()=>v,Queue:()=>y,MessageHeartbeatCommand:()=>d,MessageDequeueCommand:()=>m,MessageDeleteCommand:()=>i,MessageDeferCommand:()=>u,MessageCreateCommand:()=>l,ChannelPolicySetCommand:()=>c,ChannelPolicyClearCommand:()=>o});module.exports=W(le);var I=(e)=>{return e*1000};var T=I(0);var v=(e)=>{let t=JSON.parse(e);if(t.type===0)return{eventType:"MESSAGE_CREATED",id:t.id,delayMs:t.delay_ms};else if(t.type===1)return{eventType:"MESSAGE_DELETED",id:t.id};else if(t.type===2)return{eventType:"MESSAGE_DEFERRED",id:t.id,delayMs:t.delay_ms};else throw new Error("Unknown event type")};var _=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),z=(e)=>({nodeType:"RAW",value:e}),X=(e)=>{return`'${e.replace(/'/g,"''")}'`},J=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return X(e);else if(typeof e==="number")return e.toString();else if(typeof e==="boolean")return e?"TRUE":"FALSE";else if(e instanceof Date)return`'${e.toISOString()}'`;else if(typeof e==="bigint")return e.toString();else throw new Error(`Unsupported value type: ${typeof e}`)},j=(e)=>{return`"${e.replace(/"/g,'""')}"`},K=(e)=>{if(e.nodeType==="VALUE")return J(e.value);else if(e.nodeType==="REF")return j(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var n=(e,...t)=>{let a=[];for(let r=0;r<e.length;r+=1)if(a.push(e[r]),r<t.length)a.push(K(t[r]));return z(a.join(""))};class o{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
2
|
+
SELECT 1 FROM ${s(this.schema)}."channel_policy_clear"(
|
|
3
3
|
$1
|
|
4
4
|
)
|
|
5
|
-
`.value,[this.channelName])}}class
|
|
6
|
-
SELECT 1 FROM ${
|
|
5
|
+
`.value,[this.channelName])}}class c{schema;channelName;maxConcurrency;releaseIntervalMs;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName;let t=e.maxConcurrency??null;this.maxConcurrency=t!==null?Math.max(0,t):null;let a=e.releaseIntervalMs??null;this.releaseIntervalMs=a!==null?Math.max(0,a):null,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
6
|
+
SELECT 1 FROM ${s(this.schema)}."channel_policy_set"(
|
|
7
7
|
$1,
|
|
8
8
|
$2::INTEGER,
|
|
9
9
|
$3::INTEGER
|
|
10
10
|
)
|
|
11
|
-
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}var
|
|
12
|
-
SELECT 1 FROM ${
|
|
11
|
+
`.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}var L=require("crypto"),U=()=>{return L.randomBytes(16).toString("base64url")};var C=require("node:crypto");class l{schema;channelName;content;id;delayMs;createdAt;constructor(e){let t=e.delayMs===void 0?T:e.delayMs;this.id=C.randomUUID(),this.schema=e.schema,this.channelName=e.channelName??U(),this.content=e.content,this.delayMs=t,this.createdAt=new Date}async execute(e){await e.query(n`
|
|
12
|
+
SELECT 1 FROM ${s(this.schema)}."message_create"(
|
|
13
13
|
$1,
|
|
14
14
|
$2,
|
|
15
15
|
$3,
|
|
16
|
-
$4::BIGINT
|
|
17
|
-
$5::BIGINT
|
|
16
|
+
$4::BIGINT
|
|
18
17
|
)
|
|
19
|
-
`.value,[this.id,this.channelName,this.content,this.
|
|
18
|
+
`.value,[this.id,this.channelName,this.content,this.delayMs])}}class m{schema;lockMs;constructor(e){this.schema=e.schema,this.lockMs=e.lockMs}async execute(e){let t=await e.query(n`
|
|
20
19
|
SELECT
|
|
21
20
|
result_code,
|
|
22
21
|
metadata,
|
|
23
22
|
content,
|
|
24
23
|
state
|
|
25
|
-
FROM ${
|
|
26
|
-
`.value,[]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE",retryMs:t.metadata.retry_ms};else if(t.result_code===1)return{resultType:"MESSAGE_DEQUEUED",message:{id:t.metadata.id,channelName:t.metadata.channel_name,isUnlocked:t.metadata.is_unlocked,content:t.content,state:t.state,numAttempts:t.metadata.num_attempts}};else throw new Error("Unexpected dequeue result")}}class i{schema;id;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.numAttempts=e.numAttempts}async execute(e){let t=await e.query(
|
|
27
|
-
SELECT * FROM ${
|
|
24
|
+
FROM ${s(this.schema)}."message_dequeue"($1::BIGINT)
|
|
25
|
+
`.value,[this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE",retryMs:t.metadata.retry_ms};else if(t.result_code===1)return{resultType:"MESSAGE_DEQUEUED",message:{id:t.metadata.id,channelName:t.metadata.channel_name,isUnlocked:t.metadata.is_unlocked,content:t.content,state:t.state,numAttempts:t.metadata.num_attempts}};else throw new Error("Unexpected dequeue result")}}class i{schema;id;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.numAttempts=e.numAttempts}async execute(e){let t=await e.query(n`
|
|
26
|
+
SELECT * FROM ${s(this.schema)}."message_delete"(
|
|
28
27
|
$1,
|
|
29
28
|
$2::BIGINT
|
|
30
29
|
)
|
|
31
|
-
`.value,[this.id,this.numAttempts]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}class u{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?
|
|
32
|
-
SELECT * FROM ${
|
|
30
|
+
`.value,[this.id,this.numAttempts]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}class u{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?T:e.delayMs;this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id,this.delayMs=t,this.state=e.state??null}async execute(e){let t=await e.query(n`
|
|
31
|
+
SELECT * FROM ${s(this.schema)}."message_defer"(
|
|
33
32
|
$1,
|
|
34
33
|
$2::BIGINT,
|
|
35
34
|
$3::BIGINT,
|
|
36
35
|
$4
|
|
37
36
|
)
|
|
38
|
-
`.value,[this.id,this.numAttempts,this.delayMs,this.state]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DEFERRED"};else throw new Error("Unexpected result")}}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
`.value,[this.id,this.numAttempts,this.delayMs,this.state]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DEFERRED"};else throw new Error("Unexpected result")}}class d{schema;id;numAttempts;lockMs;constructor(e){this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id,this.lockMs=e.lockMs}async execute(e){let t=await e.query(n`
|
|
38
|
+
SELECT * FROM ${s(this.schema)}."message_heartbeat"(
|
|
39
|
+
$1,
|
|
40
|
+
$2::BIGINT,
|
|
41
|
+
$3::BIGINT
|
|
42
|
+
)
|
|
43
|
+
`.value,[this.id,this.numAttempts,this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var O=(e)=>{let t=e.split(`
|
|
44
|
+
`),a=Number.MAX_SAFE_INTEGER;for(let r of t){if(r.trim().length===0)continue;let k=r.search(/\S/);a=Math.min(a,k)}return t.map((r)=>r.slice(a)).join(`
|
|
45
|
+
`).trim()};var S=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",ne=S.dirname(S.dirname(__filename)),ae=new RegExp(`^${ne}/`),E=(e)=>{return e.replace(ae,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/00-table-channel-policy.ts",f={name:E(__filename),sql:(e)=>{let t=[e.schema,"channel_policy_name_ux"].join("_");return[n`
|
|
46
|
+
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
42
47
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
43
48
|
"name" TEXT NOT NULL,
|
|
44
49
|
"max_concurrency" INTEGER,
|
|
@@ -46,11 +51,11 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
46
51
|
"created_at" TIMESTAMP NOT NULL,
|
|
47
52
|
PRIMARY KEY ("id")
|
|
48
53
|
);
|
|
49
|
-
`,
|
|
50
|
-
CREATE UNIQUE INDEX
|
|
51
|
-
ON ${
|
|
52
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",
|
|
53
|
-
CREATE TABLE ${
|
|
54
|
+
`,n`
|
|
55
|
+
CREATE UNIQUE INDEX ${s(t)}
|
|
56
|
+
ON ${s(e.schema)}."channel_policy" ("name");
|
|
57
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",G={name:E(__filename),sql:(e)=>{let t=[e.schema,"channel_state_name_ux"].join("_"),a=[e.schema,"channel_state_dequeue_ix"].join("_");return[n`
|
|
58
|
+
CREATE TABLE ${s(e.schema)}."channel_state" (
|
|
54
59
|
"id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
|
|
55
60
|
"name" TEXT NOT NULL,
|
|
56
61
|
"max_concurrency" INTEGER,
|
|
@@ -65,23 +70,22 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
65
70
|
"created_at" TIMESTAMP NOT NULL,
|
|
66
71
|
PRIMARY KEY ("id")
|
|
67
72
|
);
|
|
68
|
-
`,
|
|
69
|
-
CREATE UNIQUE INDEX
|
|
70
|
-
ON ${
|
|
71
|
-
`,
|
|
72
|
-
CREATE INDEX
|
|
73
|
-
ON ${
|
|
73
|
+
`,n`
|
|
74
|
+
CREATE UNIQUE INDEX ${s(t)}
|
|
75
|
+
ON ${s(e.schema)}."channel_state" ("name");
|
|
76
|
+
`,n`
|
|
77
|
+
CREATE INDEX ${s(a)}
|
|
78
|
+
ON ${s(e.schema)}."channel_state" (
|
|
74
79
|
"active_next_at" ASC
|
|
75
80
|
) WHERE "message_id" IS NOT NULL
|
|
76
81
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
|
|
77
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",q={name:E(__filename),sql:(e)=>{return[
|
|
78
|
-
CREATE TABLE ${
|
|
82
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",q={name:E(__filename),sql:(e)=>{return[n`
|
|
83
|
+
CREATE TABLE ${s(e.schema)}."message" (
|
|
79
84
|
"id" UUID NOT NULL,
|
|
80
85
|
"channel_name" TEXT NOT NULL,
|
|
81
86
|
"seq_no" BIGSERIAL NOT NULL,
|
|
82
87
|
"content" BYTEA NOT NULL,
|
|
83
88
|
"state" BYTEA,
|
|
84
|
-
"lock_ms" BIGINT NOT NULL,
|
|
85
89
|
"is_locked" BOOLEAN NOT NULL,
|
|
86
90
|
"num_attempts" BIGINT NOT NULL,
|
|
87
91
|
"dequeue_at" TIMESTAMP NOT NULL,
|
|
@@ -89,24 +93,23 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
89
93
|
"created_at" TIMESTAMP NOT NULL,
|
|
90
94
|
PRIMARY KEY ("id")
|
|
91
95
|
);
|
|
92
|
-
`,
|
|
96
|
+
`,n`
|
|
93
97
|
CREATE INDEX "message_dequeue_ix"
|
|
94
|
-
ON ${
|
|
98
|
+
ON ${s(e.schema)}."message" (
|
|
95
99
|
"channel_name",
|
|
96
100
|
"dequeue_at" ASC,
|
|
97
101
|
"seq_no" ASC
|
|
98
102
|
) WHERE NOT "is_locked";
|
|
99
|
-
`,
|
|
103
|
+
`,n`
|
|
100
104
|
CREATE INDEX "message_locked_dequeue_ix"
|
|
101
|
-
ON ${
|
|
105
|
+
ON ${s(e.schema)}."message" (
|
|
102
106
|
"unlock_at" ASC
|
|
103
107
|
) WHERE "is_locked";
|
|
104
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",x={name:E(__filename),sql:(e)=>{return[
|
|
105
|
-
CREATE FUNCTION ${
|
|
108
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",x={name:E(__filename),sql:(e)=>{return[n`
|
|
109
|
+
CREATE FUNCTION ${s(e.schema)}."message_create" (
|
|
106
110
|
p_id UUID,
|
|
107
111
|
p_channel_name TEXT,
|
|
108
112
|
p_content BYTEA,
|
|
109
|
-
p_lock_ms BIGINT,
|
|
110
113
|
p_delay_ms BIGINT
|
|
111
114
|
) RETURNS VOID AS $$
|
|
112
115
|
DECLARE
|
|
@@ -117,11 +120,10 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
117
120
|
BEGIN
|
|
118
121
|
v_now := NOW();
|
|
119
122
|
|
|
120
|
-
INSERT INTO ${
|
|
123
|
+
INSERT INTO ${s(e.schema)}."message" (
|
|
121
124
|
"id",
|
|
122
125
|
"channel_name",
|
|
123
126
|
"content",
|
|
124
|
-
"lock_ms",
|
|
125
127
|
"is_locked",
|
|
126
128
|
"num_attempts",
|
|
127
129
|
"dequeue_at",
|
|
@@ -130,7 +132,6 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
130
132
|
p_id,
|
|
131
133
|
p_channel_name,
|
|
132
134
|
p_content,
|
|
133
|
-
p_lock_ms,
|
|
134
135
|
FALSE,
|
|
135
136
|
0,
|
|
136
137
|
v_now + INTERVAL '1 MILLISECOND' * p_delay_ms,
|
|
@@ -144,12 +145,12 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
144
145
|
SELECT
|
|
145
146
|
"channel_policy"."max_concurrency",
|
|
146
147
|
"channel_policy"."release_interval_ms"
|
|
147
|
-
FROM ${
|
|
148
|
+
FROM ${s(e.schema)}."channel_policy"
|
|
148
149
|
WHERE "name" = p_channel_name
|
|
149
150
|
FOR SHARE
|
|
150
151
|
INTO v_channel_policy;
|
|
151
152
|
|
|
152
|
-
INSERT INTO ${
|
|
153
|
+
INSERT INTO ${s(e.schema)}."channel_state" (
|
|
153
154
|
"name",
|
|
154
155
|
"current_concurrency",
|
|
155
156
|
"current_size",
|
|
@@ -184,7 +185,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
184
185
|
v_message."dequeue_at" < v_channel_state."message_dequeue_at" OR
|
|
185
186
|
v_message."dequeue_at" = v_channel_state."message_dequeue_at" AND v_message."seq_no" < v_channel_state."message_seq_no"
|
|
186
187
|
THEN
|
|
187
|
-
UPDATE ${
|
|
188
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
188
189
|
"current_size" = v_channel_state."current_size" + 1,
|
|
189
190
|
"message_id" = v_message."id",
|
|
190
191
|
"message_dequeue_at" = v_message."dequeue_at",
|
|
@@ -195,16 +196,16 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
195
196
|
)
|
|
196
197
|
WHERE "id" = v_channel_state."id";
|
|
197
198
|
ELSE
|
|
198
|
-
UPDATE ${
|
|
199
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
199
200
|
"current_size" = v_channel_state."current_size" + 1
|
|
200
201
|
WHERE "id" = v_channel_state."id";
|
|
201
202
|
END IF;
|
|
202
203
|
|
|
203
|
-
IF ${
|
|
204
|
+
IF ${_(e.eventChannel!==null)} THEN
|
|
204
205
|
PERFORM PG_NOTIFY(
|
|
205
|
-
${
|
|
206
|
+
${_(e.eventChannel)},
|
|
206
207
|
JSON_BUILD_OBJECT(
|
|
207
|
-
'type', ${
|
|
208
|
+
'type', ${_(0)},
|
|
208
209
|
'id', p_id,
|
|
209
210
|
'delay_ms', p_delay_ms
|
|
210
211
|
)::TEXT
|
|
@@ -212,20 +213,19 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
212
213
|
END IF;
|
|
213
214
|
END;
|
|
214
215
|
$$ LANGUAGE plpgsql;
|
|
215
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/04-function-message-dequeue.ts",
|
|
216
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/04-function-message-dequeue.ts",re=(e)=>n`
|
|
216
217
|
SELECT
|
|
217
218
|
"message"."id",
|
|
218
219
|
"message"."state",
|
|
219
220
|
"message"."content",
|
|
220
221
|
"message"."channel_name",
|
|
221
|
-
"message"."lock_ms",
|
|
222
222
|
"message"."unlock_at",
|
|
223
223
|
"message"."num_attempts"
|
|
224
|
-
FROM ${
|
|
224
|
+
FROM ${s(e.schema)}."message"
|
|
225
225
|
WHERE "is_locked"
|
|
226
226
|
AND "unlock_at" <= ${e.now}
|
|
227
227
|
ORDER BY "unlock_at" ASC
|
|
228
|
-
`,
|
|
228
|
+
`,_e=(e)=>n`
|
|
229
229
|
SELECT
|
|
230
230
|
"channel_state"."id",
|
|
231
231
|
"channel_state"."name",
|
|
@@ -234,21 +234,23 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
234
234
|
"channel_state"."active_next_at",
|
|
235
235
|
"channel_state"."active_prev_at",
|
|
236
236
|
"channel_state"."current_concurrency"
|
|
237
|
-
FROM ${
|
|
237
|
+
FROM ${s(e.schema)}."channel_state"
|
|
238
238
|
WHERE "message_id" IS NOT NULL
|
|
239
239
|
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
240
240
|
ORDER BY "active_next_at" ASC
|
|
241
|
-
`,
|
|
241
|
+
`,Ee=(e)=>n`
|
|
242
242
|
SELECT
|
|
243
243
|
"message"."id",
|
|
244
244
|
"message"."dequeue_at",
|
|
245
245
|
"message"."seq_no"
|
|
246
|
-
FROM ${
|
|
246
|
+
FROM ${s(e.schema)}."message"
|
|
247
247
|
WHERE NOT "is_locked"
|
|
248
248
|
AND "channel_name" = ${e.channelName}
|
|
249
249
|
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
250
|
-
|
|
251
|
-
CREATE FUNCTION ${
|
|
250
|
+
`,$={name:E(__filename),sql:(e)=>{let t=re({now:n`v_now`,schema:e.schema}),a=Ee({channelName:n`v_channel_state."name"`,schema:e.schema}),r=_e({schema:e.schema});return[n`
|
|
251
|
+
CREATE FUNCTION ${s(e.schema)}."message_dequeue" (
|
|
252
|
+
p_lock_ms BIGINT
|
|
253
|
+
)
|
|
252
254
|
RETURNS TABLE (
|
|
253
255
|
result_code INTEGER,
|
|
254
256
|
content BYTEA,
|
|
@@ -271,13 +273,13 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
271
273
|
INTO v_message_locked;
|
|
272
274
|
|
|
273
275
|
IF v_message_locked."id" IS NOT NULL THEN
|
|
274
|
-
UPDATE ${
|
|
276
|
+
UPDATE ${s(e.schema)}."message" SET
|
|
275
277
|
"num_attempts" = v_message_locked."num_attempts" + 1,
|
|
276
|
-
"unlock_at" = v_now + (
|
|
278
|
+
"unlock_at" = v_now + (p_lock_ms * INTERVAL '1 millisecond')
|
|
277
279
|
WHERE "id" = v_message_locked."id";
|
|
278
280
|
|
|
279
281
|
RETURN QUERY SELECT
|
|
280
|
-
${
|
|
282
|
+
${_(1)},
|
|
281
283
|
v_message_locked.content,
|
|
282
284
|
v_message_locked.state,
|
|
283
285
|
JSON_BUILD_OBJECT(
|
|
@@ -289,7 +291,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
289
291
|
RETURN;
|
|
290
292
|
END IF;
|
|
291
293
|
|
|
292
|
-
${
|
|
294
|
+
${r}
|
|
293
295
|
FOR UPDATE
|
|
294
296
|
SKIP LOCKED
|
|
295
297
|
LIMIT 1
|
|
@@ -297,7 +299,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
297
299
|
|
|
298
300
|
IF v_channel_state."id" IS NULL THEN
|
|
299
301
|
RETURN QUERY SELECT
|
|
300
|
-
${
|
|
302
|
+
${_(0)},
|
|
301
303
|
NULL::BYTEA,
|
|
302
304
|
NULL::BYTEA,
|
|
303
305
|
JSON_BUILD_OBJECT('retry_ms', NULL);
|
|
@@ -306,7 +308,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
306
308
|
|
|
307
309
|
IF v_channel_state."active_next_at" > v_now THEN
|
|
308
310
|
RETURN QUERY SELECT
|
|
309
|
-
${
|
|
311
|
+
${_(0)},
|
|
310
312
|
NULL::BYTEA,
|
|
311
313
|
NULL::BYTEA,
|
|
312
314
|
JSON_BUILD_OBJECT(
|
|
@@ -320,16 +322,15 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
320
322
|
"message"."channel_name",
|
|
321
323
|
"message"."content",
|
|
322
324
|
"message"."num_attempts",
|
|
323
|
-
"message"."state"
|
|
324
|
-
|
|
325
|
-
FROM ${n(e.schema)}."message"
|
|
325
|
+
"message"."state"
|
|
326
|
+
FROM ${s(e.schema)}."message"
|
|
326
327
|
WHERE "id" = v_channel_state."message_id"
|
|
327
328
|
INTO v_message_dequeue;
|
|
328
329
|
|
|
329
|
-
UPDATE ${
|
|
330
|
+
UPDATE ${s(e.schema)}."message" SET
|
|
330
331
|
"is_locked" = TRUE,
|
|
331
332
|
"num_attempts" = v_message_dequeue."num_attempts" + 1,
|
|
332
|
-
"unlock_at" = v_now + (
|
|
333
|
+
"unlock_at" = v_now + (p_lock_ms * INTERVAL '1 millisecond')
|
|
333
334
|
WHERE "id" = v_message_dequeue."id";
|
|
334
335
|
|
|
335
336
|
${a}
|
|
@@ -337,13 +338,13 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
337
338
|
INTO v_message_next;
|
|
338
339
|
|
|
339
340
|
IF v_message_next."id" IS NULL THEN
|
|
340
|
-
UPDATE ${
|
|
341
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
341
342
|
"current_concurrency" = v_channel_state."current_concurrency" + 1,
|
|
342
343
|
"active_prev_at" = v_now,
|
|
343
344
|
"message_id" = NULL
|
|
344
345
|
WHERE "id" = v_channel_state."id";
|
|
345
346
|
ELSE
|
|
346
|
-
UPDATE ${
|
|
347
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
347
348
|
"current_concurrency" = v_channel_state."current_concurrency" + 1,
|
|
348
349
|
"message_id" = v_message_next."id",
|
|
349
350
|
"message_dequeue_at" = v_message_next."dequeue_at",
|
|
@@ -357,7 +358,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
357
358
|
END IF;
|
|
358
359
|
|
|
359
360
|
RETURN QUERY SELECT
|
|
360
|
-
${
|
|
361
|
+
${_(1)},
|
|
361
362
|
v_message_dequeue.content,
|
|
362
363
|
v_message_dequeue.state,
|
|
363
364
|
JSON_BUILD_OBJECT(
|
|
@@ -369,8 +370,8 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
369
370
|
RETURN;
|
|
370
371
|
END;
|
|
371
372
|
$$ LANGUAGE plpgsql;
|
|
372
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts"
|
|
373
|
-
CREATE FUNCTION ${
|
|
373
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts",F={name:E(__filename),sql:(e)=>{return[n`
|
|
374
|
+
CREATE FUNCTION ${s(e.schema)}."message_delete" (
|
|
374
375
|
p_id UUID,
|
|
375
376
|
p_num_attempts BIGINT
|
|
376
377
|
)
|
|
@@ -387,24 +388,24 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
387
388
|
"message"."channel_name",
|
|
388
389
|
"message"."num_attempts",
|
|
389
390
|
"message"."is_locked"
|
|
390
|
-
FROM ${
|
|
391
|
+
FROM ${s(e.schema)}."message"
|
|
391
392
|
WHERE "id" = p_id
|
|
392
393
|
FOR UPDATE
|
|
393
394
|
INTO v_message;
|
|
394
395
|
|
|
395
396
|
IF v_message."id" IS NULL THEN
|
|
396
397
|
RETURN QUERY SELECT
|
|
397
|
-
${
|
|
398
|
+
${_(0)};
|
|
398
399
|
RETURN;
|
|
399
400
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
400
401
|
RETURN QUERY SELECT
|
|
401
|
-
${
|
|
402
|
+
${_(1)};
|
|
402
403
|
RETURN;
|
|
403
404
|
END IF;
|
|
404
405
|
|
|
405
406
|
SELECT
|
|
406
407
|
"channel_policy"."id"
|
|
407
|
-
FROM ${
|
|
408
|
+
FROM ${s(e.schema)}."channel_policy"
|
|
408
409
|
WHERE "name" = v_message."channel_name"
|
|
409
410
|
FOR SHARE
|
|
410
411
|
INTO v_channel_policy;
|
|
@@ -413,41 +414,41 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
413
414
|
"channel_state"."id",
|
|
414
415
|
"channel_state"."current_size",
|
|
415
416
|
"channel_state"."current_concurrency"
|
|
416
|
-
FROM ${
|
|
417
|
+
FROM ${s(e.schema)}."channel_state"
|
|
417
418
|
WHERE "name" = v_message."channel_name"
|
|
418
419
|
FOR UPDATE
|
|
419
420
|
INTO v_channel_state;
|
|
420
421
|
|
|
421
422
|
IF v_channel_policy."id" IS NULL AND v_channel_state."current_size" = 1 THEN
|
|
422
|
-
DELETE FROM ${
|
|
423
|
+
DELETE FROM ${s(e.schema)}."channel_state"
|
|
423
424
|
WHERE "id" = v_channel_state."id";
|
|
424
425
|
ELSE
|
|
425
|
-
UPDATE ${
|
|
426
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
426
427
|
"current_concurrency" = v_channel_state."current_concurrency" - 1,
|
|
427
428
|
"current_size" = v_channel_state."current_size" - 1
|
|
428
429
|
WHERE "id" = v_channel_state."id";
|
|
429
430
|
END IF;
|
|
430
431
|
|
|
431
|
-
IF ${
|
|
432
|
+
IF ${_(e.eventChannel!==null)} THEN
|
|
432
433
|
PERFORM PG_NOTIFY(
|
|
433
|
-
${
|
|
434
|
+
${_(e.eventChannel)},
|
|
434
435
|
JSON_BUILD_OBJECT(
|
|
435
|
-
'type', ${
|
|
436
|
+
'type', ${_(1)},
|
|
436
437
|
'id', p_id
|
|
437
438
|
)::TEXT
|
|
438
439
|
);
|
|
439
440
|
END IF;
|
|
440
441
|
|
|
441
|
-
DELETE FROM ${
|
|
442
|
+
DELETE FROM ${s(e.schema)}."message"
|
|
442
443
|
WHERE "id" = p_id;
|
|
443
444
|
|
|
444
445
|
RETURN QUERY SELECT
|
|
445
|
-
${
|
|
446
|
+
${_(2)};
|
|
446
447
|
RETURN;
|
|
447
448
|
END;
|
|
448
449
|
$$ LANGUAGE plpgsql;
|
|
449
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",
|
|
450
|
-
CREATE FUNCTION ${
|
|
450
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",b={name:E(__filename),sql:(e)=>{return[n`
|
|
451
|
+
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
451
452
|
p_id UUID,
|
|
452
453
|
p_num_attempts BIGINT,
|
|
453
454
|
p_delay_ms BIGINT,
|
|
@@ -470,18 +471,18 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
470
471
|
"message"."num_attempts",
|
|
471
472
|
"message"."is_locked",
|
|
472
473
|
"message"."seq_no"
|
|
473
|
-
FROM ${
|
|
474
|
+
FROM ${s(e.schema)}."message"
|
|
474
475
|
WHERE "id" = p_id
|
|
475
476
|
FOR UPDATE
|
|
476
477
|
INTO v_message;
|
|
477
478
|
|
|
478
479
|
IF v_message."id" IS NULL THEN
|
|
479
480
|
RETURN QUERY SELECT
|
|
480
|
-
${
|
|
481
|
+
${_(0)};
|
|
481
482
|
RETURN;
|
|
482
483
|
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
483
484
|
RETURN QUERY SELECT
|
|
484
|
-
${
|
|
485
|
+
${_(1)};
|
|
485
486
|
RETURN;
|
|
486
487
|
END IF;
|
|
487
488
|
|
|
@@ -492,7 +493,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
492
493
|
"channel_state"."message_dequeue_at",
|
|
493
494
|
"channel_state"."active_prev_at",
|
|
494
495
|
"channel_state"."message_seq_no"
|
|
495
|
-
FROM ${
|
|
496
|
+
FROM ${s(e.schema)}."channel_state"
|
|
496
497
|
WHERE "name" = v_message."channel_name"
|
|
497
498
|
FOR UPDATE
|
|
498
499
|
INTO v_channel_state;
|
|
@@ -504,7 +505,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
504
505
|
v_dequeue_at < v_channel_state."message_dequeue_at" OR
|
|
505
506
|
v_dequeue_at = v_channel_state."message_dequeue_at" AND v_message."seq_no" < v_channel_state."message_seq_no"
|
|
506
507
|
THEN
|
|
507
|
-
UPDATE ${
|
|
508
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
508
509
|
"current_concurrency" = v_channel_state."current_concurrency" - 1,
|
|
509
510
|
"message_id" = v_message."id",
|
|
510
511
|
"message_dequeue_at" = v_dequeue_at,
|
|
@@ -515,22 +516,22 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
515
516
|
)
|
|
516
517
|
WHERE "name" = v_message."channel_name";
|
|
517
518
|
ELSE
|
|
518
|
-
UPDATE ${
|
|
519
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
519
520
|
"current_concurrency" = v_channel_state."current_concurrency" - 1
|
|
520
521
|
WHERE "name" = v_message."channel_name";
|
|
521
522
|
END IF;
|
|
522
523
|
|
|
523
|
-
UPDATE ${
|
|
524
|
+
UPDATE ${s(e.schema)}."message" SET
|
|
524
525
|
"state" = p_state,
|
|
525
526
|
"is_locked" = FALSE,
|
|
526
527
|
"dequeue_at" = v_dequeue_at
|
|
527
528
|
WHERE "id" = p_id;
|
|
528
529
|
|
|
529
|
-
IF ${
|
|
530
|
+
IF ${_(e.eventChannel!==null)} THEN
|
|
530
531
|
PERFORM PG_NOTIFY(
|
|
531
|
-
${
|
|
532
|
+
${_(e.eventChannel)},
|
|
532
533
|
JSON_BUILD_OBJECT(
|
|
533
|
-
'type', ${
|
|
534
|
+
'type', ${_(2)},
|
|
534
535
|
'delay_ms', p_delay_ms,
|
|
535
536
|
'id', p_id
|
|
536
537
|
)::TEXT
|
|
@@ -538,41 +539,41 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
538
539
|
END IF;
|
|
539
540
|
|
|
540
541
|
RETURN QUERY SELECT
|
|
541
|
-
${
|
|
542
|
+
${_(2)};
|
|
542
543
|
RETURN;
|
|
543
544
|
END;
|
|
544
545
|
$$ LANGUAGE plpgsql;
|
|
545
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",
|
|
546
|
-
CREATE FUNCTION ${
|
|
546
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",B={name:E(__filename),sql:(e)=>{return[n`
|
|
547
|
+
CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
|
|
547
548
|
p_name TEXT
|
|
548
549
|
) RETURNS VOID AS $$
|
|
549
550
|
DECLARE
|
|
550
551
|
v_channel_state RECORD;
|
|
551
552
|
BEGIN
|
|
552
|
-
DELETE FROM ${
|
|
553
|
+
DELETE FROM ${s(e.schema)}."channel_policy"
|
|
553
554
|
WHERE "name" = p_name;
|
|
554
555
|
|
|
555
556
|
SELECT
|
|
556
557
|
"channel_state"."id",
|
|
557
558
|
"channel_state"."current_size"
|
|
558
|
-
FROM ${
|
|
559
|
+
FROM ${s(e.schema)}."channel_state"
|
|
559
560
|
WHERE "name" = p_name
|
|
560
561
|
FOR UPDATE
|
|
561
562
|
INTO v_channel_state;
|
|
562
563
|
|
|
563
564
|
IF v_channel_state."current_size" = 0 THEN
|
|
564
|
-
DELETE FROM ${
|
|
565
|
+
DELETE FROM ${s(e.schema)}."channel_state"
|
|
565
566
|
WHERE "id" = v_channel_state."id";
|
|
566
567
|
ELSE
|
|
567
|
-
UPDATE ${
|
|
568
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
568
569
|
"max_concurrency" = NULL,
|
|
569
570
|
"release_interval_ms" = NULL
|
|
570
571
|
WHERE "name" = p_name;
|
|
571
572
|
END IF;
|
|
572
573
|
END;
|
|
573
574
|
$$ LANGUAGE plpgsql;
|
|
574
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",
|
|
575
|
-
CREATE FUNCTION ${
|
|
575
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",H={name:E(__filename),sql:(e)=>{return[n`
|
|
576
|
+
CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
|
|
576
577
|
p_name TEXT,
|
|
577
578
|
p_max_concurrency INTEGER,
|
|
578
579
|
p_release_interval_ms INTEGER
|
|
@@ -582,7 +583,7 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
582
583
|
BEGIN
|
|
583
584
|
v_now := NOW();
|
|
584
585
|
|
|
585
|
-
INSERT INTO ${
|
|
586
|
+
INSERT INTO ${s(e.schema)}."channel_policy" (
|
|
586
587
|
"name",
|
|
587
588
|
"max_concurrency",
|
|
588
589
|
"release_interval_ms",
|
|
@@ -596,10 +597,60 @@ var{defineProperty:T,getOwnPropertyNames:w,getOwnPropertyDescriptor:P}=Object,Q=
|
|
|
596
597
|
"max_concurrency" = EXCLUDED."max_concurrency",
|
|
597
598
|
"release_interval_ms" = EXCLUDED."release_interval_ms";
|
|
598
599
|
|
|
599
|
-
UPDATE ${
|
|
600
|
+
UPDATE ${s(e.schema)}."channel_state" SET
|
|
600
601
|
"max_concurrency" = p_max_concurrency,
|
|
601
602
|
"release_interval_ms" = p_release_interval_ms
|
|
602
603
|
WHERE "name" = p_name;
|
|
603
604
|
END;
|
|
604
605
|
$$ LANGUAGE plpgsql;
|
|
605
|
-
`]}};class
|
|
606
|
+
`]}};class R{schema;channelName;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,channelName:this.channelName,content:e.content,delayMs:e.delayMs});return await a.execute(t),{messageId:a.id}}}class A{schema;adaptor;channelName;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}set(e){let t=this.adaptor(e.databaseClient);return new c({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,releaseIntervalMs:e.releaseIntervalMs}).execute(t)}clear(e){let t=this.adaptor(e.databaseClient);return new o({schema:this.schema,channelName:this.channelName}).execute(t)}}class g{policy;message;constructor(e){this.message=new R({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new A({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class p{schema;adaptor;id;isUnlocked;channelName;content;state;numAttempts;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.id=e.id,this.channelName=e.channelName,this.isUnlocked=e.isUnlocked,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){let t=this.adaptor(e.databaseClient);return new u({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs,state:e.state}).execute(t)}async delete(e){let t=this.adaptor(e.databaseClient);return new i({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(t)}async heatbeat(e){let t=this.adaptor(e.databaseClient);return new d({schema:this.schema,id:this.id,numAttempts:this.numAttempts,lockMs:e.lockMs}).execute(t)}}class D{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,content:e.content,delayMs:e.delayMs});return await a.execute(t),{messageId:a.id,channelName:a.channelName}}}var __filename="/home/runner/work/lonnymq/lonnymq/src/install/07-function-message-heartbeat.ts",w={name:E(__filename),sql:(e)=>{return[n`
|
|
607
|
+
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
608
|
+
p_id UUID,
|
|
609
|
+
p_num_attempts BIGINT,
|
|
610
|
+
p_lock_ms BIGINT
|
|
611
|
+
)
|
|
612
|
+
RETURNS TABLE (
|
|
613
|
+
result_code INTEGER
|
|
614
|
+
) AS $$
|
|
615
|
+
DECLARE
|
|
616
|
+
v_now TIMESTAMP;
|
|
617
|
+
v_channel_state RECORD;
|
|
618
|
+
v_message RECORD;
|
|
619
|
+
v_dequeue_at TIMESTAMP;
|
|
620
|
+
BEGIN
|
|
621
|
+
v_now := NOW();
|
|
622
|
+
|
|
623
|
+
SELECT
|
|
624
|
+
"message"."id",
|
|
625
|
+
"message"."channel_name",
|
|
626
|
+
"message"."num_attempts",
|
|
627
|
+
"message"."is_locked",
|
|
628
|
+
"message"."unlock_at"
|
|
629
|
+
FROM ${s(e.schema)}."message"
|
|
630
|
+
WHERE "id" = p_id
|
|
631
|
+
FOR UPDATE
|
|
632
|
+
INTO v_message;
|
|
633
|
+
|
|
634
|
+
IF v_message."id" IS NULL THEN
|
|
635
|
+
RETURN QUERY SELECT
|
|
636
|
+
${_(0)};
|
|
637
|
+
RETURN;
|
|
638
|
+
ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
|
|
639
|
+
RETURN QUERY SELECT
|
|
640
|
+
${_(1)};
|
|
641
|
+
RETURN;
|
|
642
|
+
END IF;
|
|
643
|
+
|
|
644
|
+
UPDATE ${s(e.schema)}."message" SET
|
|
645
|
+
"unlock_at" = GREATEST(
|
|
646
|
+
v_now + (p_lock_ms * INTERVAL '1 millisecond'),
|
|
647
|
+
v_message."unlock_at"
|
|
648
|
+
)
|
|
649
|
+
WHERE "id" = p_id;
|
|
650
|
+
|
|
651
|
+
RETURN QUERY SELECT
|
|
652
|
+
${_(2)};
|
|
653
|
+
RETURN;
|
|
654
|
+
END;
|
|
655
|
+
$$ LANGUAGE plpgsql;
|
|
656
|
+
`]}};class y{schema;message;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t,this.message=new D({schema:this.schema,adaptor:this.adaptor})}async dequeue(e){let t=new m({schema:this.schema,lockMs:e.lockMs}),a=this.adaptor(e.databaseClient),r=await t.execute(a);if(r.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new p({schema:this.schema,adaptor:this.adaptor,id:r.message.id,channelName:r.message.channelName,isUnlocked:r.message.isUnlocked,content:r.message.content,state:r.message.state,numAttempts:r.message.numAttempts})};else return r}channel(e){return new g({adaptor:this.adaptor,schema:this.schema,channelName:e})}install(e={}){return[f,G,q,x,$,F,b,w,H,B].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>O(t.value))}}
|