@joystick.js/node-canary 0.0.0-canary.321 → 0.0.0-canary.323

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.
@@ -21,7 +21,10 @@ var queues_default = {
21
21
  },
22
22
  getJobs: function(query = {}) {
23
23
  const db = this.db?.collection(`queue_${this.queue.name}`);
24
- return db.find(query).toArray();
24
+ return db.find({
25
+ ...query,
26
+ environment: process.env.NODE_ENV
27
+ }).toArray();
25
28
  },
26
29
  getNextJobToRun: async function() {
27
30
  const db = this.db?.collection(`queue_${this.queue.name}`);
@@ -29,11 +32,13 @@ var queues_default = {
29
32
  $or: [
30
33
  {
31
34
  status: "pending",
35
+ environment: process.env.NODE_ENV,
32
36
  nextRunAt: { $lte: new Date().toISOString() },
33
37
  lockedBy: { $exists: false }
34
38
  },
35
39
  {
36
40
  status: "pending",
41
+ environment: process.env.NODE_ENV,
37
42
  nextRunAt: { $lte: new Date().toISOString() },
38
43
  lockedBy: null
39
44
  }
@@ -56,6 +61,7 @@ var queues_default = {
56
61
  const indexes = await this.db?.collection(`queue_${this.queue.name}`).indexes();
57
62
  db.createIndex({ status: 1 });
58
63
  db.createIndex({ status: 1, nextRunAt: 1 });
64
+ db.createIndex({ status: 1, environment: 1, nextRunAt: 1, lockedBy: 1 });
59
65
  if (this.queue.options?.cleanup?.completedAfterSeconds) {
60
66
  if (indexes?.find((index) => index?.name === "completedAt_1")) {
61
67
  await db.dropIndex({ completedAt: 1 });
@@ -110,7 +116,10 @@ var queues_default = {
110
116
  },
111
117
  setJobsForMachinePending: function() {
112
118
  const db = this.db?.collection(`queue_${this.queue.name}`);
113
- return db.updateMany({ status: { $in: ["pending", "running"] }, lockedBy: this.machineId }, {
119
+ return db.updateMany({
120
+ status: { $in: ["pending", "running"] },
121
+ lockedBy: this.machineId
122
+ }, {
114
123
  $set: {
115
124
  status: "pending"
116
125
  },
@@ -9,9 +9,10 @@ var handleCleanupQueues_default = async ({
9
9
  seconds = 0
10
10
  }) => {
11
11
  const jobs_with_status = await database.query(`
12
- SELECT * FROM ${table} WHERE status = ANY($1)
12
+ SELECT * FROM ${table} WHERE status = ANY($1) AND environment = $2
13
13
  `, [
14
- ["completed", "failed"]
14
+ ["completed", "failed"],
15
+ process.env.NODE_ENV
15
16
  ]);
16
17
  const jobs_to_cleanup = jobs_with_status?.filter((job = {}) => {
17
18
  if (job?.status === "completed") {
@@ -7,16 +7,18 @@ var queues_default = {
7
7
  INSERT INTO queue_${this.queue.name} (
8
8
  _id,
9
9
  status,
10
+ environment,
10
11
  job,
11
12
  payload,
12
13
  next_run_at,
13
14
  attempts
14
15
  ) VALUES (
15
- $1, $2, $3, $4, $5, $6
16
+ $1, $2, $3, $4, $5, $6, $7
16
17
  )
17
18
  `, [
18
19
  jobToAdd?._id,
19
20
  jobToAdd?.status,
21
+ jobToAdd?.environment,
20
22
  jobToAdd?.job,
21
23
  JSON.stringify(jobToAdd?.payload),
22
24
  jobToAdd?.nextRunAt,
@@ -70,9 +72,12 @@ var queues_default = {
70
72
  ${query?.status ? `
71
73
  WHERE
72
74
  status = $1
75
+ AND
76
+ environment = $2
73
77
  ` : ""}
74
78
  `, [
75
- query?.status
79
+ query?.status,
80
+ process.env.NODE_ENV
76
81
  ]);
77
82
  },
78
83
  getNextJobToRun: async function() {
@@ -83,13 +88,16 @@ var queues_default = {
83
88
  WHERE
84
89
  status = $1
85
90
  AND
86
- next_run_at::timestamp <= $2
91
+ environment = $2
92
+ AND
93
+ next_run_at::timestamp <= $3
87
94
  AND
88
95
  locked_by IS NULL
89
96
  ORDER BY
90
97
  next_run_at ASC
91
98
  `, [
92
99
  "pending",
100
+ process.env.NODE_ENV,
93
101
  new Date().toISOString()
94
102
  ]);
95
103
  if (nextJob?._id) {
@@ -120,6 +128,7 @@ var queues_default = {
120
128
  CREATE TABLE IF NOT EXISTS queue_${this.queue.name} (
121
129
  _id text PRIMARY KEY,
122
130
  status text,
131
+ environment text,
123
132
  job text,
124
133
  payload text,
125
134
  next_run_at text,
@@ -132,8 +141,10 @@ var queues_default = {
132
141
  )
133
142
  `);
134
143
  db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS attempts smallint`);
144
+ db?.query(`ALTER TABLE queue_${this.queue.name} ADD COLUMN IF NOT EXISTS environment text`);
135
145
  db?.query(`CREATE INDEX IF NOT EXISTS status_index ON queue_${this.queue.name} (status)`);
136
146
  db?.query(`CREATE INDEX IF NOT EXISTS status_nextRunAt_index ON queue_${this.queue.name} (status, next_run_at)`);
147
+ db?.query(`CREATE INDEX IF NOT EXISTS nextJob_index ON queue_${this.queue.name} (status, environment, next_run_at, locked_by)`);
137
148
  db?.query(`CREATE INDEX IF NOT EXISTS completedAt_index ON queue_${this.queue.name} (completed_at)`);
138
149
  db?.query(`CREATE INDEX IF NOT EXISTS failedAt_index ON queue_${this.queue.name} (failed_at)`);
139
150
  if (this.queue.options?.cleanup?.completedAfterSeconds) {
@@ -56,6 +56,7 @@ class Queue {
56
56
  this.db.addJob({
57
57
  _id: generateId(),
58
58
  status: "pending",
59
+ environment: process.env.NODE_ENV,
59
60
  ...options,
60
61
  nextRunAt
61
62
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.321",
3
+ "version": "0.0.0-canary.323",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",