@iterativeflow/mysql 2.0.0-alpha.7 → 2.0.0-alpha.9
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.mjs +14 -5
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -12,17 +12,26 @@ const createMysqlQueue = (sql, t, id) => {
|
|
|
12
12
|
opts?.priority ?? 0
|
|
13
13
|
]);
|
|
14
14
|
},
|
|
15
|
-
async claim({ limit, leaseMs, now }) {
|
|
15
|
+
async claim({ limit, leaseMs, now, names }) {
|
|
16
|
+
if (names && names.length === 0) return [];
|
|
16
17
|
const at = ms(now);
|
|
17
18
|
const expiresAt = new Date(at + leaseMs);
|
|
18
19
|
return sql.tx(async (tx) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
ORDER BY priority, run_at LIMIT ? FOR UPDATE SKIP LOCKED`, [
|
|
20
|
+
const namePredicate = names ? ` AND r.name IN (${names.map(() => "?").join(",")})` : "";
|
|
21
|
+
const params = names ? [
|
|
22
22
|
at,
|
|
23
23
|
at,
|
|
24
|
+
...names,
|
|
24
25
|
limit
|
|
25
|
-
]
|
|
26
|
+
] : [
|
|
27
|
+
at,
|
|
28
|
+
at,
|
|
29
|
+
limit
|
|
30
|
+
];
|
|
31
|
+
const due = await tx.query(`SELECT j.run_id AS run_id, j.version AS version
|
|
32
|
+
FROM ${t.job} j LEFT JOIN ${t.run} r ON r.id = j.run_id
|
|
33
|
+
WHERE j.run_at <= ? AND (j.lease_expires IS NULL OR j.lease_expires <= ?)${namePredicate}
|
|
34
|
+
ORDER BY j.priority, j.run_at LIMIT ? FOR UPDATE OF j SKIP LOCKED`, params);
|
|
26
35
|
const leases = [];
|
|
27
36
|
for (const row of due) {
|
|
28
37
|
const token = `${id()}:${row.run_id}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iterativeflow/mysql",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"build": "tsdown"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@iterativeflow/core": "2.0.0-alpha.
|
|
31
|
+
"@iterativeflow/core": "2.0.0-alpha.9"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"mysql2": ">=3.0.0"
|