@pgpm/database-jobs 0.26.0 → 0.26.2

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/Makefile CHANGED
@@ -1,5 +1,5 @@
1
1
  EXTENSION = pgpm-database-jobs
2
- DATA = sql/pgpm-database-jobs--0.22.0.sql
2
+ DATA = sql/pgpm-database-jobs--0.26.1.sql
3
3
 
4
4
  PG_CONFIG = pg_config
5
5
  PGXS := $(shell $(PG_CONFIG) --pgxs)
@@ -13,7 +13,10 @@ CREATE FUNCTION app_jobs.add_job (
13
13
  queue_name text DEFAULT NULL,
14
14
  run_at timestamptz DEFAULT now(),
15
15
  max_attempts integer DEFAULT 25,
16
- priority integer DEFAULT 0
16
+ priority integer DEFAULT 0,
17
+ entity_id uuid DEFAULT NULL,
18
+ organization_id uuid DEFAULT NULL,
19
+ entity_type text DEFAULT NULL
17
20
  )
18
21
  RETURNS app_jobs.jobs
19
22
  AS $$
@@ -31,6 +34,9 @@ BEGIN
31
34
  INSERT INTO app_jobs.jobs (
32
35
  database_id,
33
36
  actor_id,
37
+ entity_id,
38
+ organization_id,
39
+ entity_type,
34
40
  task_identifier,
35
41
  payload,
36
42
  queue_name,
@@ -41,6 +47,9 @@ BEGIN
41
47
  ) VALUES (
42
48
  v_database_id,
43
49
  v_actor_id,
50
+ add_job.entity_id,
51
+ add_job.organization_id,
52
+ add_job.entity_type,
44
53
  identifier,
45
54
  coalesce(payload, '{}'::json),
46
55
  queue_name,
@@ -84,6 +93,9 @@ BEGIN
84
93
  INSERT INTO app_jobs.jobs (
85
94
  database_id,
86
95
  actor_id,
96
+ entity_id,
97
+ organization_id,
98
+ entity_type,
87
99
  task_identifier,
88
100
  payload,
89
101
  queue_name,
@@ -93,6 +105,9 @@ BEGIN
93
105
  ) VALUES (
94
106
  v_database_id,
95
107
  v_actor_id,
108
+ add_job.entity_id,
109
+ add_job.organization_id,
110
+ add_job.entity_type,
96
111
  identifier,
97
112
  payload,
98
113
  queue_name,
@@ -14,7 +14,8 @@ CREATE FUNCTION app_jobs.add_scheduled_job(
14
14
  job_key text DEFAULT NULL,
15
15
  queue_name text DEFAULT NULL,
16
16
  max_attempts integer DEFAULT 25,
17
- priority integer DEFAULT 0
17
+ priority integer DEFAULT 0,
18
+ entity_id uuid DEFAULT NULL
18
19
  )
19
20
  RETURNS app_jobs.scheduled_jobs
20
21
  AS $$
@@ -32,6 +33,7 @@ BEGIN
32
33
  INSERT INTO app_jobs.scheduled_jobs (
33
34
  database_id,
34
35
  actor_id,
36
+ entity_id,
35
37
  task_identifier,
36
38
  payload,
37
39
  queue_name,
@@ -42,6 +44,7 @@ BEGIN
42
44
  ) VALUES (
43
45
  v_database_id,
44
46
  v_actor_id,
47
+ add_scheduled_job.entity_id,
45
48
  identifier,
46
49
  coalesce(payload, '{}'::json),
47
50
  queue_name,
@@ -81,6 +84,7 @@ BEGIN
81
84
  INSERT INTO app_jobs.scheduled_jobs (
82
85
  database_id,
83
86
  actor_id,
87
+ entity_id,
84
88
  task_identifier,
85
89
  payload,
86
90
  queue_name,
@@ -90,6 +94,7 @@ BEGIN
90
94
  ) VALUES (
91
95
  v_database_id,
92
96
  v_actor_id,
97
+ add_scheduled_job.entity_id,
93
98
  identifier,
94
99
  payload,
95
100
  queue_name,
@@ -42,6 +42,7 @@ BEGIN
42
42
  INSERT INTO app_jobs.jobs (
43
43
  database_id,
44
44
  actor_id,
45
+ entity_id,
45
46
  queue_name,
46
47
  task_identifier,
47
48
  payload,
@@ -51,6 +52,7 @@ BEGIN
51
52
  ) SELECT
52
53
  database_id,
53
54
  actor_id,
55
+ entity_id,
54
56
  queue_name,
55
57
  task_identifier,
56
58
  payload,
@@ -6,6 +6,9 @@ CREATE TABLE app_jobs.jobs (
6
6
  id bigserial PRIMARY KEY,
7
7
  database_id uuid,
8
8
  actor_id uuid,
9
+ entity_id uuid,
10
+ organization_id uuid,
11
+ entity_type text,
9
12
  queue_name text DEFAULT NULL,
10
13
  task_identifier text NOT NULL,
11
14
  payload json DEFAULT '{}' ::json NOT NULL,
@@ -30,6 +33,9 @@ COMMENT ON TABLE app_jobs.jobs IS 'Background job queue: each row is a pending o
30
33
  COMMENT ON COLUMN app_jobs.jobs.id IS 'Auto-incrementing job identifier';
31
34
  COMMENT ON COLUMN app_jobs.jobs.database_id IS 'Database this job belongs to (nullable for system-level jobs without tenant context)';
32
35
  COMMENT ON COLUMN app_jobs.jobs.actor_id IS 'User who triggered this job, read from JWT claims at enqueue time';
36
+ COMMENT ON COLUMN app_jobs.jobs.entity_id IS 'Entity (org/team) this job is scoped to for billing; NULL means platform-level (resolved via database_id → owner_id)';
37
+ COMMENT ON COLUMN app_jobs.jobs.organization_id IS 'Top-level organization for this entity; resolved at enqueue time via get_organization_id(entity_type, entity_id)';
38
+ COMMENT ON COLUMN app_jobs.jobs.entity_type IS 'Entity type prefix (org, team, app, etc.) for interpreting entity_id';
33
39
  COMMENT ON COLUMN app_jobs.jobs.queue_name IS 'Name of the queue this job belongs to; used for worker routing and concurrency control';
34
40
  COMMENT ON COLUMN app_jobs.jobs.task_identifier IS 'Identifier for the task type (maps to a worker handler function)';
35
41
  COMMENT ON COLUMN app_jobs.jobs.payload IS 'JSON payload of arguments passed to the task handler';
@@ -6,6 +6,7 @@ CREATE TABLE app_jobs.scheduled_jobs (
6
6
  id bigserial PRIMARY KEY,
7
7
  database_id uuid,
8
8
  actor_id uuid,
9
+ entity_id uuid,
9
10
  queue_name text DEFAULT NULL,
10
11
  task_identifier text NOT NULL,
11
12
  payload json DEFAULT '{}' ::json NOT NULL,
@@ -29,6 +30,7 @@ COMMENT ON TABLE app_jobs.scheduled_jobs IS 'Recurring/cron-style job definition
29
30
  COMMENT ON COLUMN app_jobs.scheduled_jobs.id IS 'Auto-incrementing scheduled job identifier';
30
31
  COMMENT ON COLUMN app_jobs.scheduled_jobs.database_id IS 'Database this scheduled job belongs to (nullable for system-level schedules without tenant context)';
31
32
  COMMENT ON COLUMN app_jobs.scheduled_jobs.actor_id IS 'User who created this scheduled job, read from JWT claims at creation time';
33
+ COMMENT ON COLUMN app_jobs.scheduled_jobs.entity_id IS 'Entity (org/team) this scheduled job is scoped to for billing; NULL means platform-level (resolved via database_id → owner_id)';
32
34
  COMMENT ON COLUMN app_jobs.scheduled_jobs.queue_name IS 'Name of the queue spawned jobs are placed into';
33
35
  COMMENT ON COLUMN app_jobs.scheduled_jobs.task_identifier IS 'Task type identifier for spawned jobs';
34
36
  COMMENT ON COLUMN app_jobs.scheduled_jobs.payload IS 'JSON payload passed to each spawned job';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpm/database-jobs",
3
- "version": "0.26.0",
3
+ "version": "0.26.2",
4
4
  "description": "Database-specific job handling and queue management",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "contributors": [
@@ -35,5 +35,5 @@
35
35
  "bugs": {
36
36
  "url": "https://github.com/constructive-io/pgpm-modules/issues"
37
37
  },
38
- "gitHead": "3badf1e5e2fc71deae9e194b779599d17ab28a0d"
38
+ "gitHead": "d938867e5d7c0e7b2e130a2bdc5d58cd0d5874e1"
39
39
  }
@@ -1,6 +1,6 @@
1
1
  # pgpm-database-jobs extension
2
2
  comment = 'pgpm-database-jobs extension'
3
- default_version = '0.22.0'
3
+ default_version = '0.26.1'
4
4
  module_pathname = '$libdir/pgpm-database-jobs'
5
5
  requires = 'plpgsql,pgcrypto,pgpm-verify,pgpm-jwt-claims'
6
6
  relocatable = false
@@ -116,6 +116,7 @@ CREATE TABLE app_jobs.scheduled_jobs (
116
116
  id bigserial PRIMARY KEY,
117
117
  database_id uuid,
118
118
  actor_id uuid,
119
+ entity_id uuid,
119
120
  queue_name text DEFAULT NULL,
120
121
  task_identifier text NOT NULL,
121
122
  payload pg_catalog.json DEFAULT '{}'::json NOT NULL,
@@ -143,6 +144,8 @@ COMMENT ON COLUMN app_jobs.scheduled_jobs.database_id IS 'Database this schedule
143
144
 
144
145
  COMMENT ON COLUMN app_jobs.scheduled_jobs.actor_id IS 'User who created this scheduled job, read from JWT claims at creation time';
145
146
 
147
+ COMMENT ON COLUMN app_jobs.scheduled_jobs.entity_id IS 'Entity (org/team) this scheduled job is scoped to for billing; NULL means platform-level (resolved via database_id → owner_id)';
148
+
146
149
  COMMENT ON COLUMN app_jobs.scheduled_jobs.queue_name IS 'Name of the queue spawned jobs are placed into';
147
150
 
148
151
  COMMENT ON COLUMN app_jobs.scheduled_jobs.task_identifier IS 'Task type identifier for spawned jobs';
@@ -189,6 +192,9 @@ CREATE TABLE app_jobs.jobs (
189
192
  id bigserial PRIMARY KEY,
190
193
  database_id uuid,
191
194
  actor_id uuid,
195
+ entity_id uuid,
196
+ organization_id uuid,
197
+ entity_type text,
192
198
  queue_name text DEFAULT NULL,
193
199
  task_identifier text NOT NULL,
194
200
  payload pg_catalog.json DEFAULT '{}'::json NOT NULL,
@@ -218,6 +224,12 @@ COMMENT ON COLUMN app_jobs.jobs.database_id IS 'Database this job belongs to (nu
218
224
 
219
225
  COMMENT ON COLUMN app_jobs.jobs.actor_id IS 'User who triggered this job, read from JWT claims at enqueue time';
220
226
 
227
+ COMMENT ON COLUMN app_jobs.jobs.entity_id IS 'Entity (org/team) this job is scoped to for billing; NULL means platform-level (resolved via database_id → owner_id)';
228
+
229
+ COMMENT ON COLUMN app_jobs.jobs.organization_id IS 'Top-level organization for this entity; resolved at enqueue time via get_organization_id(entity_type, entity_id)';
230
+
231
+ COMMENT ON COLUMN app_jobs.jobs.entity_type IS 'Entity type prefix (org, team, app, etc.) for interpreting entity_id';
232
+
221
233
  COMMENT ON COLUMN app_jobs.jobs.queue_name IS 'Name of the queue this job belongs to; used for worker routing and concurrency control';
222
234
 
223
235
  COMMENT ON COLUMN app_jobs.jobs.task_identifier IS 'Identifier for the task type (maps to a worker handler function)';
@@ -402,6 +414,7 @@ BEGIN
402
414
  INSERT INTO app_jobs.jobs (
403
415
  database_id,
404
416
  actor_id,
417
+ entity_id,
405
418
  queue_name,
406
419
  task_identifier,
407
420
  payload,
@@ -411,6 +424,7 @@ BEGIN
411
424
  ) SELECT
412
425
  database_id,
413
426
  actor_id,
427
+ entity_id,
414
428
  queue_name,
415
429
  task_identifier,
416
430
  payload,
@@ -672,7 +686,7 @@ BEGIN
672
686
  END;
673
687
  $EOFCODE$;
674
688
 
675
- CREATE FUNCTION app_jobs.add_scheduled_job(identifier text, payload pg_catalog.json DEFAULT '{}'::json, schedule_info pg_catalog.json DEFAULT '{}'::json, job_key text DEFAULT NULL, queue_name text DEFAULT NULL, max_attempts int DEFAULT 25, priority int DEFAULT 0) RETURNS app_jobs.scheduled_jobs AS $EOFCODE$
689
+ CREATE FUNCTION app_jobs.add_scheduled_job(identifier text, payload pg_catalog.json DEFAULT '{}'::json, schedule_info pg_catalog.json DEFAULT '{}'::json, job_key text DEFAULT NULL, queue_name text DEFAULT NULL, max_attempts int DEFAULT 25, priority int DEFAULT 0, entity_id uuid DEFAULT NULL) RETURNS app_jobs.scheduled_jobs AS $EOFCODE$
676
690
  DECLARE
677
691
  v_job app_jobs.scheduled_jobs;
678
692
  v_database_id uuid;
@@ -687,6 +701,7 @@ BEGIN
687
701
  INSERT INTO app_jobs.scheduled_jobs (
688
702
  database_id,
689
703
  actor_id,
704
+ entity_id,
690
705
  task_identifier,
691
706
  payload,
692
707
  queue_name,
@@ -697,6 +712,7 @@ BEGIN
697
712
  ) VALUES (
698
713
  v_database_id,
699
714
  v_actor_id,
715
+ add_scheduled_job.entity_id,
700
716
  identifier,
701
717
  coalesce(payload, '{}'::json),
702
718
  queue_name,
@@ -736,6 +752,7 @@ BEGIN
736
752
  INSERT INTO app_jobs.scheduled_jobs (
737
753
  database_id,
738
754
  actor_id,
755
+ entity_id,
739
756
  task_identifier,
740
757
  payload,
741
758
  queue_name,
@@ -745,6 +762,7 @@ BEGIN
745
762
  ) VALUES (
746
763
  v_database_id,
747
764
  v_actor_id,
765
+ add_scheduled_job.entity_id,
748
766
  identifier,
749
767
  payload,
750
768
  queue_name,
@@ -756,7 +774,7 @@ BEGIN
756
774
  END;
757
775
  $EOFCODE$ LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
758
776
 
759
- CREATE FUNCTION app_jobs.add_job(identifier text, payload pg_catalog.json DEFAULT '{}'::json, job_key text DEFAULT NULL, queue_name text DEFAULT NULL, run_at timestamptz DEFAULT now(), max_attempts int DEFAULT 25, priority int DEFAULT 0) RETURNS app_jobs.jobs AS $EOFCODE$
777
+ CREATE FUNCTION app_jobs.add_job(identifier text, payload pg_catalog.json DEFAULT '{}'::json, job_key text DEFAULT NULL, queue_name text DEFAULT NULL, run_at timestamptz DEFAULT now(), max_attempts int DEFAULT 25, priority int DEFAULT 0, entity_id uuid DEFAULT NULL, organization_id uuid DEFAULT NULL, entity_type text DEFAULT NULL) RETURNS app_jobs.jobs AS $EOFCODE$
760
778
  DECLARE
761
779
  v_job app_jobs.jobs;
762
780
  v_database_id uuid;
@@ -771,6 +789,9 @@ BEGIN
771
789
  INSERT INTO app_jobs.jobs (
772
790
  database_id,
773
791
  actor_id,
792
+ entity_id,
793
+ organization_id,
794
+ entity_type,
774
795
  task_identifier,
775
796
  payload,
776
797
  queue_name,
@@ -781,6 +802,9 @@ BEGIN
781
802
  ) VALUES (
782
803
  v_database_id,
783
804
  v_actor_id,
805
+ add_job.entity_id,
806
+ add_job.organization_id,
807
+ add_job.entity_type,
784
808
  identifier,
785
809
  coalesce(payload, '{}'::json),
786
810
  queue_name,
@@ -824,6 +848,9 @@ BEGIN
824
848
  INSERT INTO app_jobs.jobs (
825
849
  database_id,
826
850
  actor_id,
851
+ entity_id,
852
+ organization_id,
853
+ entity_type,
827
854
  task_identifier,
828
855
  payload,
829
856
  queue_name,
@@ -833,6 +860,9 @@ BEGIN
833
860
  ) VALUES (
834
861
  v_database_id,
835
862
  v_actor_id,
863
+ add_job.entity_id,
864
+ add_job.organization_id,
865
+ add_job.entity_type,
836
866
  identifier,
837
867
  payload,
838
868
  queue_name,