pnscheduler 0.0.1 → 0.2.0

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/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Persistent NodeJS Scheduler - A simple job scheduler for Node.js applications, with Postgres-based persistence.
4
4
 
5
+ ![npm-version](https://img.shields.io/npm/v/pnscheduler)
6
+ ![Build](https://img.shields.io/github/actions/workflow/status/nilmus/pnscheduler/test.yml)
7
+
5
8
  ## Installation
6
9
 
7
10
  ```bash
@@ -78,7 +81,7 @@ await scheduler.scheduleJob("parameterized-job", new Date(2084, 0, 1), {
78
81
  });
79
82
 
80
83
  // With grace period (5 minutes)
81
- await scheduler.scheduleJob("simple-job", new Date(2084, 0, 1), null, 300_000);
84
+ await scheduler.scheduleJob("simple-job", new Date(2084, 0, 1), null, 300);
82
85
  ```
83
86
 
84
87
  ### Job Management
@@ -103,8 +106,8 @@ console.log(dueJobs);
103
106
  ### Scheduler Control
104
107
 
105
108
  ```typescript
106
- // Start the scheduler (30s check interval)
107
- scheduler.start(3000);
109
+ // Adjust check frequency (defaults to 1 second)
110
+ scheduler.start(30); // check every 30 seconds
108
111
 
109
112
  // Stop the scheduler
110
113
  scheduler.stop();
@@ -13,6 +13,7 @@ export const migrationQuery = db.query(`
13
13
  grace_period INTEGER,
14
14
  params JSONB,
15
15
  status pnscheduler.status_type DEFAULT 'pending' NOT NULL,
16
+ status_updated_at TIMESTAMPTZ,
16
17
  created_at TIMESTAMPTZ DEFAULT NOW()
17
18
  )
18
19
  `);
package/dist/jobs.d.ts CHANGED
@@ -6,6 +6,7 @@ type JobRow = {
6
6
  grace_period: number | null;
7
7
  params: any | null;
8
8
  status: JobStatus;
9
+ status_updated_at: Date | null;
9
10
  };
10
11
  export declare class Job {
11
12
  id: number;
@@ -14,6 +15,7 @@ export declare class Job {
14
15
  gracePeriod: number | null;
15
16
  params: any;
16
17
  status: JobStatus;
17
- constructor({ id, name, execution_date, grace_period, params, status, }: JobRow);
18
+ statusUpdatedAt: Date | null;
19
+ constructor({ id, name, execution_date, grace_period, params, status, status_updated_at, }: JobRow);
18
20
  }
19
21
  export {};
package/dist/jobs.js CHANGED
@@ -14,6 +14,9 @@ function validateJobRow(row) {
14
14
  if (typeof row.status !== "string" ||
15
15
  !["pending", "executed", "failed", "skipped"].includes(row.status))
16
16
  throw new Error(`Invalid job row column: status - ${row.status}`);
17
+ if (row.status_updated_at !== null &&
18
+ !(row.status_updated_at instanceof Date))
19
+ throw new Error(`Invalid job row column: status_updated_at - ${row.status_updated_at}`);
17
20
  return row;
18
21
  }
19
22
  export class Job {
@@ -23,7 +26,8 @@ export class Job {
23
26
  gracePeriod;
24
27
  params;
25
28
  status;
26
- constructor({ id, name, execution_date, grace_period, params, status, }) {
29
+ statusUpdatedAt;
30
+ constructor({ id, name, execution_date, grace_period, params, status, status_updated_at, }) {
27
31
  const row = validateJobRow({
28
32
  id,
29
33
  name,
@@ -31,6 +35,7 @@ export class Job {
31
35
  grace_period,
32
36
  params,
33
37
  status,
38
+ status_updated_at,
34
39
  });
35
40
  this.id = row.id;
36
41
  this.name = row.name;
@@ -38,5 +43,6 @@ export class Job {
38
43
  this.gracePeriod = row.grace_period;
39
44
  this.params = row.params;
40
45
  this.status = row.status;
46
+ this.statusUpdatedAt = row.status_updated_at;
41
47
  }
42
48
  }
package/dist/scheduler.js CHANGED
@@ -59,10 +59,7 @@ class PNScheduler {
59
59
  }
60
60
  async #markJobStatusAs(job, status) {
61
61
  this.#log(`Marking job "${job.name}" with id ${job.id} as ${status}...`);
62
- await db.query(`UPDATE pnscheduler.jobs SET status = $1 WHERE id = $2`, [
63
- status,
64
- job.id,
65
- ]);
62
+ await db.query(`UPDATE pnscheduler.jobs SET status = $1, status_updated_at = NOW() WHERE id = $2`, [status, job.id]);
66
63
  }
67
64
  async findDueJobs() {
68
65
  this.#log("Finding due jobs...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pnscheduler",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Persistent NodeJS Scheduler - A simple job scheduler for Node.js applications, with Postgres-based persistence.",
5
5
  "keywords": [
6
6
  "node",