@iterativeflow/mysql 2.0.1 → 2.1.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +14 -2
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -17,7 +17,7 @@ const createMysqlQueue = (sql, t, id) => {
17
17
  const at = ms(now);
18
18
  const expiresAt = new Date(at + leaseMs);
19
19
  return sql.tx(async (tx) => {
20
- const namePredicate = names ? ` AND r.name IN (${names.map(() => "?").join(",")})` : "";
20
+ const namePredicate = names ? ` AND (r.name IS NULL OR r.name IN (${names.map(() => "?").join(",")}))` : "";
21
21
  const params = names ? [
22
22
  at,
23
23
  at,
@@ -191,7 +191,19 @@ const ddl = (prefix = "") => {
191
191
  next_run_at BIGINT NOT NULL,
192
192
  last_run_at BIGINT,
193
193
  KEY cron_due (next_run_at)
194
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`
194
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
195
+ `DROP FUNCTION IF EXISTS \`${prefix}pending_work\``,
196
+ `CREATE FUNCTION \`${prefix}pending_work\`(flow_names JSON, as_of BIGINT)
197
+ RETURNS BIGINT READS SQL DATA
198
+ RETURN (
199
+ (SELECT COUNT(*) FROM ${t.job} j LEFT JOIN ${t.run} r ON r.id = j.run_id
200
+ WHERE j.run_at <= as_of AND (j.lease_expires IS NULL OR j.lease_expires <= as_of)
201
+ AND (flow_names IS NULL OR JSON_CONTAINS(flow_names, JSON_QUOTE(r.name))))
202
+ + (SELECT COUNT(*) FROM ${t.timer} tm LEFT JOIN ${t.run} r ON r.id = tm.run_id
203
+ WHERE tm.fire_at <= as_of AND (flow_names IS NULL OR JSON_CONTAINS(flow_names, JSON_QUOTE(r.name))))
204
+ + (SELECT COUNT(*) FROM ${t.cron} c
205
+ WHERE c.next_run_at <= as_of AND (flow_names IS NULL OR JSON_CONTAINS(flow_names, JSON_QUOTE(c.flow_name))))
206
+ )`
195
207
  ];
196
208
  };
197
209
  /** Apply the schema DDL (idempotent). Run once before use. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iterativeflow/mysql",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@iterativeflow/core": "2.0.1"
28
+ "@iterativeflow/core": "2.1.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "mysql2": ">=3.0.0"