postjob 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be82d81ed82917e5d476d559a18fa3c6946d7041
4
- data.tar.gz: 382982f885ea11cf7dea7bc8a7086e29a637bc0d
3
+ metadata.gz: 375c8b8cb2b29ba963463113fa303d53374222fd
4
+ data.tar.gz: 5feceb4be5f5c97eba91caffd55f73d70469aa0c
5
5
  SHA512:
6
- metadata.gz: b403fcb4a9a0caebeaadab7845062e696219d119a40cffaf97ccf1b8071960dd0b1aad32a3628532fddb7adf3b980018118c74ddb97fa70c9beff1f5126b5303
7
- data.tar.gz: f8ab70060f8287a4d5a742647662568e4bba5a104b1d21796a327245742f61a2b4a7ff3f98aa569fa91618e2102c564cca408baeb3497bd5e455321f29828456
6
+ metadata.gz: 02cb7b0d90750a13f859c925fccb9fea90af194cd71efcff329be0aa9274195531e2c2892ebaa0a549bc66f470c648b848fab6c697781fc8273265c55ebf09ae
7
+ data.tar.gz: e663a86782d31c2c84e8039bd373103151fb38685b2973d362ddff5b6bd7dd15943c374ecbe94106c04c16d2519bb084556159418f8aa382442b73c52994674b
@@ -6,23 +6,23 @@ CREATE OR REPLACE FUNCTION {SCHEMA_NAME}._wakeup_runners() RETURNS TRIGGER AS $$
6
6
  $$ LANGUAGE plpgsql;
7
7
 
8
8
  BEGIN;
9
- DROP TRIGGER IF EXISTS _wakeup_runners ON {TABLE_NAME};
9
+ DROP TRIGGER IF EXISTS _wakeup_runners ON {SCHEMA_NAME}.postjobs;
10
10
 
11
11
  CREATE TRIGGER _wakeup_runners AFTER INSERT OR UPDATE
12
- ON {TABLE_NAME}
12
+ ON {SCHEMA_NAME}.postjobs
13
13
  FOR EACH STATEMENT
14
14
  EXECUTE PROCEDURE {SCHEMA_NAME}._wakeup_runners();
15
15
  COMMIT;
16
16
 
17
17
  CREATE OR REPLACE FUNCTION {SCHEMA_NAME}._wakeup_parent_job(job_id BIGINT) RETURNS VOID AS $$
18
18
  BEGIN
19
- UPDATE postjobs
19
+ UPDATE {SCHEMA_NAME}.postjobs
20
20
  SET
21
21
  status='ready',
22
22
  next_run_at=(now() at time zone 'utc'),
23
23
  updated_at=(now() at time zone 'utc')
24
24
  WHERE
25
25
  status='sleep'
26
- AND id=(SELECT parent_id FROM postjobs WHERE id=job_id);
26
+ AND id=(SELECT parent_id FROM {SCHEMA_NAME}.postjobs WHERE id=job_id);
27
27
  END;
28
28
  $$ LANGUAGE plpgsql;
@@ -31,14 +31,14 @@ AS $$
31
31
  ) RETURNING {SCHEMA_NAME}.postjobs.id INTO job_id;
32
32
 
33
33
  -- fill in root_id and full_id ------------------------------------
34
- UPDATE postjobs
34
+ UPDATE {SCHEMA_NAME}.postjobs
35
35
  SET
36
- root_id=COALESCE((SELECT root_id FROM postjobs s WHERE s.id=postjobs.parent_id), id),
37
- full_id=COALESCE((SELECT full_id FROM postjobs s WHERE s.id=postjobs.parent_id) || '.' || id, id::varchar)
36
+ root_id=COALESCE((SELECT root_id FROM {SCHEMA_NAME}.postjobs s WHERE s.id=postjobs.parent_id), id),
37
+ full_id=COALESCE((SELECT full_id FROM {SCHEMA_NAME}.postjobs s WHERE s.id=postjobs.parent_id) || '.' || id, id::varchar)
38
38
  WHERE id=job_id;
39
39
 
40
40
  -- return the job -------------------------------------------------
41
41
  RETURN QUERY
42
- SELECT * FROM postjobs WHERE id=job_id;
42
+ SELECT * FROM {SCHEMA_NAME}.postjobs WHERE id=job_id;
43
43
  END;
44
44
  $$ LANGUAGE plpgsql;
@@ -20,7 +20,7 @@ DECLARE
20
20
  BEGIN
21
21
  v_pid := pg_backend_pid();
22
22
 
23
- UPDATE postjobs
23
+ UPDATE {SCHEMA_NAME}.postjobs
24
24
  SET
25
25
  status='processing',
26
26
  processing_client=(SELECT client_addr || ':' || client_port FROM pg_stat_activity WHERE pid = v_pid),
@@ -37,7 +37,7 @@ $$ LANGUAGE plpgsql;
37
37
 
38
38
  CREATE OR REPLACE FUNCTION {SCHEMA_NAME}._reset_job_processing(job_id BIGINT) RETURNS VOID AS $$
39
39
  BEGIN
40
- UPDATE postjobs
40
+ UPDATE {SCHEMA_NAME}.postjobs
41
41
  SET
42
42
  processing_client=NULL,
43
43
  processing_client_identifier=NULL,
@@ -1,7 +1,7 @@
1
1
  CREATE OR REPLACE FUNCTION {SCHEMA_NAME}._update_job_version(job_id BIGINT, p_version VARCHAR) RETURNS VOID AS $$
2
2
  BEGIN
3
3
  IF p_version IS NOT NULL THEN
4
- UPDATE postjobs
4
+ UPDATE {SCHEMA_NAME}.postjobs
5
5
  SET
6
6
  workflow_version=p_version,
7
7
  updated_at=(now() at time zone 'utc')
@@ -12,10 +12,10 @@ $$ LANGUAGE plpgsql;
12
12
 
13
13
  CREATE OR REPLACE FUNCTION {SCHEMA_NAME}.set_job_result(job_id BIGINT, p_results JSONB, p_version VARCHAR) RETURNS VOID AS $$
14
14
  BEGIN
15
- PERFORM _update_job_version(job_id, p_version);
16
- PERFORM _reset_job_processing(job_id);
15
+ PERFORM {SCHEMA_NAME}._update_job_version(job_id, p_version);
16
+ PERFORM {SCHEMA_NAME}._reset_job_processing(job_id);
17
17
 
18
- UPDATE postjobs
18
+ UPDATE {SCHEMA_NAME}.postjobs
19
19
  SET
20
20
  results=p_results,
21
21
  error=NULL,
@@ -25,16 +25,16 @@ BEGIN
25
25
  next_run_at=NULL
26
26
  WHERE id=job_id;
27
27
 
28
- PERFORM _wakeup_parent_job(job_id);
28
+ PERFORM {SCHEMA_NAME}._wakeup_parent_job(job_id);
29
29
  END;
30
30
  $$ LANGUAGE plpgsql;
31
31
 
32
32
  CREATE OR REPLACE FUNCTION {SCHEMA_NAME}.set_job_pending(job_id BIGINT, p_version VARCHAR) RETURNS VOID AS $$
33
33
  BEGIN
34
- PERFORM _update_job_version(job_id, p_version);
35
- PERFORM _reset_job_processing(job_id);
34
+ PERFORM {SCHEMA_NAME}._update_job_version(job_id, p_version);
35
+ PERFORM {SCHEMA_NAME}._reset_job_processing(job_id);
36
36
 
37
- UPDATE postjobs
37
+ UPDATE {SCHEMA_NAME}.postjobs
38
38
  SET status='sleep', next_run_at=NULL
39
39
  WHERE id=job_id;
40
40
  END;
@@ -56,7 +56,7 @@ BEGIN
56
56
 
57
57
  -- If this is a recoverable error we check if we have any remaining attempts.
58
58
  IF p_status = 'err' THEN
59
- IF (SELECT max_attempts - failed_attempts FROM postjobs WHERE id=job_id) > 0 THEN
59
+ IF (SELECT max_attempts - failed_attempts FROM {SCHEMA_NAME}.postjobs WHERE id=job_id) > 0 THEN
60
60
  p_status = 'err';
61
61
  ELSE
62
62
  p_status = 'failed';
@@ -64,7 +64,7 @@ BEGIN
64
64
  END IF;
65
65
 
66
66
  -- set status, clear next_run_at
67
- UPDATE postjobs
67
+ UPDATE {SCHEMA_NAME}.postjobs
68
68
  SET
69
69
  status=p_status,
70
70
  next_run_at=NULL
@@ -74,7 +74,7 @@ BEGIN
74
74
  IF p_status != 'failed' AND p_status != 'timeout' THEN
75
75
  next_run_at_basetime := CASE WHEN p_fast_mode THEN 0.01 ELSE 10 END;
76
76
 
77
- UPDATE postjobs
77
+ UPDATE {SCHEMA_NAME}.postjobs
78
78
  SET
79
79
  next_run_at=(now() at time zone 'utc') + next_run_at_basetime * pow(1.5, failed_attempts) * interval '1 second'
80
80
  WHERE id=job_id;
@@ -91,11 +91,11 @@ CREATE OR REPLACE FUNCTION {SCHEMA_NAME}.set_job_error(
91
91
  p_version VARCHAR,
92
92
  p_fast_mode BOOLEAN) RETURNS VOID AS $$
93
93
  BEGIN
94
- PERFORM _update_job_version(job_id, p_version);
95
- PERFORM _reset_job_processing(job_id);
94
+ PERFORM {SCHEMA_NAME}._update_job_version(job_id, p_version);
95
+ PERFORM {SCHEMA_NAME}._reset_job_processing(job_id);
96
96
 
97
97
  -- write error info
98
- UPDATE postjobs
98
+ UPDATE {SCHEMA_NAME}.postjobs
99
99
  SET
100
100
  error=p_error,
101
101
  error_message=p_error_message,
@@ -105,8 +105,8 @@ BEGIN
105
105
  WHERE id=job_id;
106
106
 
107
107
  -- prepare next run, if any
108
- PERFORM _prepare_next_run(job_id, p_status, p_fast_mode);
109
- PERFORM _wakeup_parent_job(job_id);
108
+ PERFORM {SCHEMA_NAME}._prepare_next_run(job_id, p_status, p_fast_mode);
109
+ PERFORM {SCHEMA_NAME}._wakeup_parent_job(job_id);
110
110
  END;
111
111
  $$ LANGUAGE plpgsql;
112
112
 
@@ -114,10 +114,10 @@ CREATE OR REPLACE FUNCTION {SCHEMA_NAME}._set_job_timeout(
114
114
  job_id BIGINT,
115
115
  p_fast_mode BOOLEAN) RETURNS VOID AS $$
116
116
  BEGIN
117
- PERFORM _reset_job_processing(job_id);
117
+ PERFORM {SCHEMA_NAME}._reset_job_processing(job_id);
118
118
 
119
119
  -- write error info
120
- UPDATE postjobs
120
+ UPDATE {SCHEMA_NAME}.postjobs
121
121
  SET
122
122
  error='Timeout',
123
123
  error_message='timeout',
@@ -127,8 +127,8 @@ BEGIN
127
127
  WHERE id=job_id;
128
128
 
129
129
  -- prepare next run, if any
130
- PERFORM _prepare_next_run(job_id, 'timeout', p_fast_mode);
131
- PERFORM _wakeup_parent_job(job_id);
130
+ PERFORM {SCHEMA_NAME}._prepare_next_run(job_id, 'timeout', p_fast_mode);
131
+ PERFORM {SCHEMA_NAME}._wakeup_parent_job(job_id);
132
132
  END;
133
133
  $$ LANGUAGE plpgsql;
134
134
 
@@ -136,12 +136,12 @@ CREATE OR REPLACE FUNCTION {SCHEMA_NAME}._set_job_zombie(
136
136
  job_id BIGINT,
137
137
  p_fast_mode BOOLEAN) RETURNS VOID AS $$
138
138
  BEGIN
139
- PERFORM _reset_job_processing(job_id);
139
+ PERFORM {SCHEMA_NAME}._reset_job_processing(job_id);
140
140
 
141
141
  RAISE NOTICE 'job % is a zombie', job_id;
142
142
 
143
143
  -- write error info
144
- UPDATE postjobs
144
+ UPDATE {SCHEMA_NAME}.postjobs
145
145
  SET
146
146
  error='Zombie',
147
147
  error_message='zombie',
@@ -151,7 +151,7 @@ BEGIN
151
151
  WHERE id=job_id;
152
152
 
153
153
  -- prepare next run, if any
154
- PERFORM _prepare_next_run(job_id, 'err', p_fast_mode);
155
- PERFORM _wakeup_parent_job(job_id);
154
+ PERFORM {SCHEMA_NAME}._prepare_next_run(job_id, 'err', p_fast_mode);
155
+ PERFORM {SCHEMA_NAME}._wakeup_parent_job(job_id);
156
156
  END;
157
157
  $$ LANGUAGE plpgsql;
@@ -6,15 +6,15 @@ DECLARE
6
6
  BEGIN
7
7
  SELECT MIN(processable_at) INTO p_processable_at FROM (
8
8
  SELECT MIN(processing_started_at + processing_max_duration * interval '1 second') AS processable_at
9
- FROM {TABLE_NAME}
9
+ FROM {SCHEMA_NAME}.postjobs
10
10
  WHERE status IN ('processing')
11
11
  UNION
12
12
  SELECT MIN(timing_out_at) AS processable_at
13
- FROM {TABLE_NAME}
13
+ FROM {SCHEMA_NAME}.postjobs
14
14
  WHERE status IN ('ready', 'err', 'sleep')
15
15
  UNION
16
16
  SELECT MIN(next_run_at) AS processable_at
17
- FROM {TABLE_NAME}
17
+ FROM {SCHEMA_NAME}.postjobs
18
18
  WHERE status IN ('ready', 'err')
19
19
  AND workflow || workflow_version = ANY ($1)
20
20
  ) sq;
@@ -24,16 +24,16 @@ END;
24
24
  $$ LANGUAGE plpgsql;
25
25
 
26
26
  CREATE OR REPLACE FUNCTION {SCHEMA_NAME}.checkout(workflows_with_versions varchar[], p_fast_mode BOOLEAN)
27
- RETURNS SETOF {TABLE_NAME}
27
+ RETURNS SETOF {SCHEMA_NAME}.postjobs
28
28
  AS $$
29
29
  DECLARE
30
- job {TABLE_NAME};
30
+ job {SCHEMA_NAME}.postjobs;
31
31
  BEGIN
32
32
  LOOP
33
33
  -- try to checkout a job. Each of the conditions here is matching
34
34
  -- one of the CASE .. WHEN clauses below.
35
35
  SELECT INTO job *
36
- FROM {TABLE_NAME} s
36
+ FROM {SCHEMA_NAME}.postjobs s
37
37
  WHERE
38
38
  (
39
39
  s.status IN ('processing')
@@ -69,8 +69,8 @@ BEGIN
69
69
  CONTINUE;
70
70
  ELSE
71
71
  -- set job to processing
72
- PERFORM _set_job_processing(job.id);
73
- RETURN QUERY SELECT * FROM {TABLE_NAME} WHERE id=job.id;
72
+ PERFORM {SCHEMA_NAME}._set_job_processing(job.id);
73
+ RETURN QUERY SELECT * FROM {SCHEMA_NAME}.postjobs WHERE id=job.id;
74
74
  EXIT;
75
75
  END CASE;
76
76
  END LOOP;
@@ -2,7 +2,7 @@ CREATE OR REPLACE FUNCTION {SCHEMA_NAME}.childjobs(v_parent_id BIGINT)
2
2
  RETURNS SETOF {SCHEMA_NAME}.postjobs AS $$
3
3
  BEGIN
4
4
  RETURN QUERY
5
- SELECT {TABLE_NAME}.* FROM {TABLE_NAME}
5
+ SELECT {SCHEMA_NAME}.postjobs.* FROM {SCHEMA_NAME}.postjobs
6
6
  WHERE parent_id=v_parent_id
7
7
  ORDER BY id;
8
8
  END;
@@ -12,7 +12,7 @@ CREATE OR REPLACE FUNCTION {SCHEMA_NAME}.next_unresolved_childjob(v_parent_id BI
12
12
  RETURNS SETOF {SCHEMA_NAME}.postjobs AS $$
13
13
  BEGIN
14
14
  RETURN QUERY
15
- SELECT {TABLE_NAME}.* FROM {TABLE_NAME}
15
+ SELECT {SCHEMA_NAME}.postjobs.* FROM {SCHEMA_NAME}.postjobs
16
16
  WHERE status NOT IN ('ok', 'failed') AND parent_id=v_parent_id
17
17
  ORDER BY next_run_at;
18
18
  END;
@@ -38,7 +38,7 @@ BEGIN
38
38
  END IF;
39
39
 
40
40
  IF v_parent_id IS NOT NULL THEN
41
- SELECT INTO parent * FROM {TABLE_NAME} WHERE id=v_parent_id;
41
+ SELECT INTO parent * FROM {SCHEMA_NAME}.postjobs WHERE id=v_parent_id;
42
42
  IF parent.id IS NULL THEN
43
43
  RAISE 'No such job: %', v_parent_id;
44
44
  END IF;
@@ -47,7 +47,7 @@ BEGIN
47
47
  -- check for existing child record
48
48
 
49
49
  -- IF v_parent_id IS NOT NULL THEN
50
- SELECT id INTO child_id FROM {TABLE_NAME}
50
+ SELECT id INTO child_id FROM {SCHEMA_NAME}.postjobs
51
51
  WHERE parent_id=v_parent_id
52
52
  AND workflow=v_workflow
53
53
  AND workflow_method=v_workflow_method
@@ -58,7 +58,7 @@ BEGIN
58
58
  -- note that RETURN QUERY does not return the function here. It 'only'
59
59
  -- adds the specified query to the result set.
60
60
  RETURN QUERY
61
- SELECT * FROM {TABLE_NAME} WHERE id=child_id
61
+ SELECT * FROM {SCHEMA_NAME}.postjobs WHERE id=child_id
62
62
  ;
63
63
  ELSE
64
64
  IF v_tags IS NOT NULL THEN
@@ -66,7 +66,7 @@ BEGIN
66
66
  END IF;
67
67
 
68
68
  RETURN QUERY
69
- SELECT * FROM enqueue(
69
+ SELECT * FROM {SCHEMA_NAME}.enqueue(
70
70
  COALESCE(v_queue, parent.queue), -- queue VARCHAR,
71
71
  v_workflow, -- workflow VARCHAR,
72
72
  v_workflow_method, -- workflow_method VARCHAR,
@@ -18,8 +18,8 @@ CREATE OR REPLACE FUNCTION {SCHEMA_NAME}.postjobs_by_token(v_token UUID)
18
18
  RETURNS SETOF {SCHEMA_NAME}.postjobs AS $$
19
19
  BEGIN
20
20
  RETURN QUERY
21
- SELECT {TABLE_NAME}.* FROM {TABLE_NAME}
22
- INNER JOIN {SCHEMA_NAME}.tokens ON {SCHEMA_NAME}.tokens.postjob_id={TABLE_NAME}.id
21
+ SELECT {SCHEMA_NAME}.postjobs.* FROM {SCHEMA_NAME}.postjobs
22
+ INNER JOIN {SCHEMA_NAME}.tokens ON {SCHEMA_NAME}.tokens.postjob_id={SCHEMA_NAME}.postjobs.id
23
23
  WHERE {SCHEMA_NAME}.tokens.token=v_token;
24
24
  END;
25
25
  $$ LANGUAGE plpgsql;
@@ -12,8 +12,6 @@ module Postjob
12
12
  # below drops that schema, and we don't want to drop the default schema.
13
13
  expect! SCHEMA_NAME != "public"
14
14
 
15
- TABLE_NAME = "#{SCHEMA_NAME}.postjobs"
16
-
17
15
  def unmigrate!
18
16
  SQL.exec "DROP SCHEMA IF EXISTS #{SCHEMA_NAME} CASCADE"
19
17
  end
@@ -29,6 +27,8 @@ module Postjob
29
27
  private
30
28
 
31
29
  def run_migration(file)
30
+ STDERR.puts "[#{file}] Running migration"
31
+
32
32
  case file
33
33
  when /\.rb$/ then run_migration_ruby(file)
34
34
  when /\.sql$/ then run_migration_sql(file)
data/lib/postjob/queue.rb CHANGED
@@ -9,8 +9,6 @@ module Postjob::Queue
9
9
  extend self
10
10
 
11
11
  SCHEMA_NAME = "postjob"
12
- TABLE_NAME = "#{SCHEMA_NAME}.postjobs"
13
-
14
12
  SQL = ::Simple::SQL
15
13
  end
16
14
 
@@ -119,7 +117,7 @@ module Postjob::Queue
119
117
  # within a single run of a job (all within the same transaction and therefore
120
118
  # invisible to the outside).
121
119
  SQL.ask <<~SQL, job.id, status
122
- UPDATE #{TABLE_NAME}
120
+ UPDATE #{SCHEMA_NAME}.postjobs
123
121
  SET workflow_status=$2
124
122
  WHERE id=$1
125
123
  SQL
@@ -32,7 +32,7 @@ describe "Postjob.process_all" do
32
32
  context "when scheduled to run in the future" do
33
33
  before do
34
34
  Simple::SQL.ask <<~SQL, id
35
- UPDATE postjobs
35
+ UPDATE postjob.postjobs
36
36
  SET next_run_at=next_run_at + interval '10 seconds'
37
37
  WHERE id=$1
38
38
  SQL
@@ -49,7 +49,7 @@ describe "Postjob.process_all" do
49
49
  context "when scheduled to time out" do
50
50
  before do
51
51
  Simple::SQL.ask <<~SQL, id
52
- UPDATE postjobs
52
+ UPDATE postjob.postjobs
53
53
  SET timing_out_at=next_run_at
54
54
  WHERE id=$1
55
55
  SQL
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postjob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel