pgbus 0.23.2 → 0.25.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/app/controllers/pgbus/deploy_tasks_controller.rb +11 -1
- data/app/helpers/pgbus/deploy_tasks_helper.rb +20 -0
- data/app/models/pgbus/deploy_task.rb +23 -1
- data/app/models/pgbus/deploy_task_run.rb +47 -5
- data/app/views/pgbus/deploy_tasks/_tasks_table.html.erb +3 -0
- data/app/views/pgbus/deploy_tasks/show.html.erb +25 -2
- data/config/i18n-tasks.yml +1 -0
- data/config/locales/da.yml +18 -0
- data/config/locales/de.yml +18 -0
- data/config/locales/en.yml +18 -0
- data/config/locales/es.yml +18 -0
- data/config/locales/fi.yml +18 -0
- data/config/locales/fr.yml +18 -0
- data/config/locales/it.yml +18 -0
- data/config/locales/ja.yml +18 -0
- data/config/locales/nb.yml +18 -0
- data/config/locales/nl.yml +18 -0
- data/config/locales/pt.yml +18 -0
- data/config/locales/sv.yml +18 -0
- data/lib/generators/pgbus/add_deploy_task_run_outcomes_generator.rb +48 -0
- data/lib/generators/pgbus/templates/add_deploy_task_run_outcomes.rb.erb +12 -0
- data/lib/generators/pgbus/templates/add_deploy_tasks_tables.rb.erb +5 -0
- data/lib/generators/pgbus/templates/deploy_tasks.yml.erb +6 -0
- data/lib/generators/pgbus/templates/migration.rb.erb +5 -0
- data/lib/pgbus/active_job/adapter.rb +13 -0
- data/lib/pgbus/active_job/deploy_task_run_id.rb +53 -0
- data/lib/pgbus/active_job/executor.rb +57 -0
- data/lib/pgbus/client.rb +19 -0
- data/lib/pgbus/deploy/dependencies.rb +115 -0
- data/lib/pgbus/deploy/runner.rb +103 -18
- data/lib/pgbus/deploy/schema.rb +65 -0
- data/lib/pgbus/deploy/task.rb +23 -5
- data/lib/pgbus/engine.rb +1 -0
- data/lib/pgbus/event_bus/registry.rb +77 -0
- data/lib/pgbus/generators/migration_detector.rb +13 -3
- data/lib/pgbus/mcp/tools/deploy_tasks_tool.rb +1 -1
- data/lib/pgbus/version.rb +1 -1
- data/lib/pgbus/web/data_source/deploy_task_list.rb +39 -6
- data/lib/pgbus/web/deploy_task_state.rb +7 -5
- data/sig/pgbus/client.rbs +2 -0
- metadata +6 -1
|
@@ -94,6 +94,7 @@ module Pgbus
|
|
|
94
94
|
add_outbox: "pgbus:add_outbox",
|
|
95
95
|
add_recurring: "pgbus:add_recurring",
|
|
96
96
|
add_deploy_tasks: "pgbus:add_deploy_tasks",
|
|
97
|
+
add_deploy_task_run_outcomes: "pgbus:add_deploy_task_run_outcomes",
|
|
97
98
|
add_workflows: "pgbus:add_workflows",
|
|
98
99
|
add_workflow_signals: "pgbus:add_workflow_signals",
|
|
99
100
|
add_failed_events_index: "pgbus:add_failed_events_index",
|
|
@@ -121,6 +122,7 @@ module Pgbus
|
|
|
121
122
|
add_outbox: "outbox entries table (transactional outbox)",
|
|
122
123
|
add_recurring: "recurring tasks + executions tables",
|
|
123
124
|
add_deploy_tasks: "deploy tasks + runs tables (one-time jobs run after a rollover)",
|
|
125
|
+
add_deploy_task_run_outcomes: "deploy task run outcomes (completed_at, failed_at) and after: dependencies",
|
|
124
126
|
add_workflows: "workflow tables (durable multi-step workflows: runs, step attempts, audit trail)",
|
|
125
127
|
add_workflow_signals: "waiting workflow steps (fan_out, wait_for: signals, wait timeouts)",
|
|
126
128
|
add_failed_events_index: "unique index on pgbus_failed_events (queue_name, msg_id)",
|
|
@@ -253,10 +255,18 @@ module Pgbus
|
|
|
253
255
|
|
|
254
256
|
# Same shape as recurring_migrations: plain create_table in the
|
|
255
257
|
# template, so the generator is queued only while a table is absent.
|
|
258
|
+
# The outcomes add-on (issue #660) follows the tables: its template
|
|
259
|
+
# adds each column if_not_exists, so queuing it after add_deploy_tasks
|
|
260
|
+
# also completes a half-present schema whose existing table lacks them.
|
|
256
261
|
def deploy_tasks_migrations
|
|
257
|
-
return []
|
|
258
|
-
|
|
259
|
-
|
|
262
|
+
return %i[add_deploy_tasks add_deploy_task_run_outcomes] unless
|
|
263
|
+
table_exists?("pgbus_deploy_tasks") && table_exists?("pgbus_deploy_task_runs")
|
|
264
|
+
|
|
265
|
+
runs = column_names("pgbus_deploy_task_runs")
|
|
266
|
+
outcomes = runs.include?("completed_at") && runs.include?("failed_at") &&
|
|
267
|
+
column_names("pgbus_deploy_tasks").include?("dependencies") &&
|
|
268
|
+
index_exists?("pgbus_deploy_task_runs", "idx_pgbus_deploy_task_runs_completed")
|
|
269
|
+
outcomes ? [] : [:add_deploy_task_run_outcomes]
|
|
260
270
|
end
|
|
261
271
|
|
|
262
272
|
# The add_workflows template uses if_not_exists throughout, so a
|
|
@@ -11,7 +11,7 @@ module Pgbus
|
|
|
11
11
|
tool_name "pgbus_deploy_tasks"
|
|
12
12
|
title "Pgbus Deploy Tasks"
|
|
13
13
|
description <<~DESC
|
|
14
|
-
Deploy tasks: one-time jobs the scheduler enqueues once every live pgbus process runs the new app revision. Lists each task's state (disabled, waiting, due, ran, never)
|
|
14
|
+
Deploy tasks: one-time jobs the scheduler enqueues once every live pgbus process runs the new app revision. Lists each task's state (disabled, waiting, due, ran, never), the rollover status the scheduler waits on, and for a task with after: its dependencies and the ones it still waits on (waiting_on, each not_run, running or failed).
|
|
15
15
|
Returns every task unless page or per_page is given; then it is
|
|
16
16
|
paginated (per_page defaults to 100, capped at 100). The response
|
|
17
17
|
carries page, per_page, total (capped at 10000 when paginated; the
|
data/lib/pgbus/version.rb
CHANGED
|
@@ -6,6 +6,8 @@ module Pgbus
|
|
|
6
6
|
# The Deploy tasks page (issue #536): declared tasks with their last
|
|
7
7
|
# rollover and manual runs, one task's run history, the rollover the
|
|
8
8
|
# scheduler acts on, and the two actions (Run now, Enable/Disable).
|
|
9
|
+
# A task with after: (issue #660) also lists the dependencies it still
|
|
10
|
+
# waits on, judged against the scheduler's revision like the rollover.
|
|
9
11
|
module DeployTaskList
|
|
10
12
|
RUN_HISTORY = 25
|
|
11
13
|
|
|
@@ -15,11 +17,13 @@ module Pgbus
|
|
|
15
17
|
def deploy_tasks(page: nil, per_page: nil)
|
|
16
18
|
return [] unless DeployTask.table_exists?
|
|
17
19
|
|
|
20
|
+
DeployTask.refresh_dependencies_column!
|
|
18
21
|
scope = DeployTask.order(:key)
|
|
19
22
|
scope = scope.limit(per_page).offset(((page || 1) - 1) * per_page) if per_page
|
|
20
23
|
records = scope.to_a
|
|
21
24
|
runs = DeployTaskRun.latest_for(records.map(&:key)).group_by(&:task_key)
|
|
22
|
-
|
|
25
|
+
waiting = deploy_waiting_on(records)
|
|
26
|
+
records.map { |record| deploy_task_row(record, runs.fetch(record.key, []), waiting) }
|
|
23
27
|
rescue StandardError => e
|
|
24
28
|
Pgbus.logger.error { "[Pgbus::Web] Error fetching deploy tasks: #{e.class}: #{e.message}" }
|
|
25
29
|
[]
|
|
@@ -28,13 +32,14 @@ module Pgbus
|
|
|
28
32
|
def deploy_task(id)
|
|
29
33
|
return nil unless DeployTask.table_exists?
|
|
30
34
|
|
|
35
|
+
DeployTask.refresh_dependencies_column!
|
|
31
36
|
record = DeployTask.find_by(id: id)
|
|
32
37
|
return nil unless record
|
|
33
38
|
|
|
34
39
|
# The state reads the same unbounded latest-per-trigger runs as the
|
|
35
40
|
# list, so a run older than the 25 shown still counts.
|
|
36
41
|
runs = DeployTaskRun.for_task(record.key).recent(RUN_HISTORY).to_a
|
|
37
|
-
deploy_task_row(record, DeployTaskRun.latest_for([record.key]).to_a).merge(
|
|
42
|
+
deploy_task_row(record, DeployTaskRun.latest_for([record.key]).to_a, deploy_waiting_on([record])).merge(
|
|
38
43
|
arguments: record.parsed_arguments,
|
|
39
44
|
runs: runs.map { |run| deploy_run_hash(run).merge(queue_name: run.queue_name, msg_id: run.msg_id) }
|
|
40
45
|
)
|
|
@@ -56,12 +61,15 @@ module Pgbus
|
|
|
56
61
|
|
|
57
62
|
# Run now: the scheduler's enqueue path with no gate and no claim. It
|
|
58
63
|
# leaves a pending rollover arm alone and records a manual run.
|
|
59
|
-
# :enqueued or :failed, the real outcome
|
|
60
|
-
|
|
64
|
+
# :enqueued or :failed, the real outcome; :blocked when the task waits
|
|
65
|
+
# on a dependency and ignore_dependencies is not set.
|
|
66
|
+
def enqueue_deploy_task_now(id, ignore_dependencies: false)
|
|
67
|
+
DeployTask.refresh_dependencies_column!
|
|
61
68
|
record = DeployTask.find_by(id: id)
|
|
62
69
|
return :failed unless record
|
|
63
70
|
# The hidden button is not the boundary: a disabled task is not run.
|
|
64
71
|
return disabled_enqueue(record) unless record.enabled
|
|
72
|
+
return :blocked if !ignore_dependencies && deploy_waiting_on([record]).fetch(record.key, []).any?
|
|
65
73
|
|
|
66
74
|
Deploy::Runner.new(config: Pgbus.configuration).enqueue(record.to_task, triggered_by: Deploy::Runner::MANUAL)
|
|
67
75
|
rescue StandardError => e
|
|
@@ -90,7 +98,25 @@ module Pgbus
|
|
|
90
98
|
:failed
|
|
91
99
|
end
|
|
92
100
|
|
|
93
|
-
|
|
101
|
+
# { key => [{ key:, state: }] } for the +records+ with after:, one
|
|
102
|
+
# query for their dependencies' rows and one for their outcomes.
|
|
103
|
+
def deploy_waiting_on(records)
|
|
104
|
+
dependents = records.to_h { |record| [record.key, record.parsed_dependencies] }.select { |_, keys| keys.any? }
|
|
105
|
+
return {} if dependents.empty? || !Deploy::Schema.outcomes?
|
|
106
|
+
|
|
107
|
+
by_key = DeployTask.where(key: dependents.values.flatten.uniq).index_by(&:key)
|
|
108
|
+
dependencies = Deploy::Dependencies.load(by_key.values, revision: deploy_dependency_revision)
|
|
109
|
+
dependents.transform_values { |keys| dependencies.waiting_on(keys, by_key) }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# The revision an every_deploy dependency must have completed on: the
|
|
113
|
+
# newest live scheduler's, as for deploy_rollover.
|
|
114
|
+
def deploy_dependency_revision
|
|
115
|
+
scheduler, revision = Deploy::Rollover.scheduler_revision
|
|
116
|
+
scheduler ? revision : Deploy::Revision.current
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def deploy_task_row(record, latest_runs, waiting = {})
|
|
94
120
|
by_trigger = latest_runs.index_by(&:triggered_by)
|
|
95
121
|
{
|
|
96
122
|
id: record.id, key: record.key, class_name: record.class_name, command: record.command,
|
|
@@ -99,6 +125,7 @@ module Pgbus
|
|
|
99
125
|
static: record.static, armed_at: record.armed_at, armed_for: record.armed_for,
|
|
100
126
|
last_rollover_run: deploy_run_hash(by_trigger[Deploy::Runner::ROLLOVER]),
|
|
101
127
|
last_manual_run: deploy_run_hash(by_trigger[Deploy::Runner::MANUAL]),
|
|
128
|
+
dependencies: record.parsed_dependencies, waiting_on: waiting.fetch(record.key, []),
|
|
102
129
|
created_at: record.created_at, updated_at: record.updated_at
|
|
103
130
|
}
|
|
104
131
|
end
|
|
@@ -106,7 +133,13 @@ module Pgbus
|
|
|
106
133
|
def deploy_run_hash(run)
|
|
107
134
|
return nil unless run
|
|
108
135
|
|
|
109
|
-
{ run_at: run.run_at, revision: run.revision, version: run.version, triggered_by: run.triggered_by
|
|
136
|
+
{ run_at: run.run_at, revision: run.revision, version: run.version, triggered_by: run.triggered_by,
|
|
137
|
+
completed_at: deploy_run_outcome(run, "completed_at"), failed_at: deploy_run_outcome(run, "failed_at") }
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# nil before the outcomes migration.
|
|
141
|
+
def deploy_run_outcome(run, column)
|
|
142
|
+
run.has_attribute?(column) ? run[column] : nil
|
|
110
143
|
end
|
|
111
144
|
end
|
|
112
145
|
end
|
|
@@ -6,8 +6,9 @@ module Pgbus
|
|
|
6
6
|
# its row and the rollover the scheduler acts on (DataSource#deploy_rollover),
|
|
7
7
|
# so the page prints the reason the scheduler waits for. Pure.
|
|
8
8
|
#
|
|
9
|
-
# States: disabled, waiting (armed, gate closed, with the gate's reason
|
|
10
|
-
#
|
|
9
|
+
# States: disabled, waiting (armed, gate closed, with the gate's reason;
|
|
10
|
+
# or gate open and an after: dependency not completed, issue #660), due
|
|
11
|
+
# (armed, gate open), ran (not armed, has a rollover run), never. A
|
|
11
12
|
# manual run is appended to any state through manual_args.
|
|
12
13
|
module DeployTaskState
|
|
13
14
|
BADGE_TONES = { "disabled" => :gray, "waiting" => :yellow, "due" => :indigo, "ran" => :green,
|
|
@@ -27,7 +28,7 @@ module Pgbus
|
|
|
27
28
|
|
|
28
29
|
def derive(row, rollover)
|
|
29
30
|
return ["disabled", row[:armed_at] ? "disabled_armed" : "disabled", {}] unless row[:enabled]
|
|
30
|
-
return armed(rollover) if row[:armed_at]
|
|
31
|
+
return armed(rollover, row[:waiting_on] || []) if row[:armed_at]
|
|
31
32
|
|
|
32
33
|
run = row[:last_rollover_run]
|
|
33
34
|
return ["never", "never", {}] unless run
|
|
@@ -35,12 +36,13 @@ module Pgbus
|
|
|
35
36
|
["ran", "ran", { ago: run[:run_at], revision: run[:revision] }]
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
def armed(rollover)
|
|
39
|
+
def armed(rollover, waiting_on)
|
|
39
40
|
return ["waiting", "waiting_unknown", {}] unless rollover
|
|
40
41
|
return ["waiting", "waiting_no_scheduler", {}] unless rollover[:scheduler]
|
|
41
42
|
|
|
42
43
|
case rollover[:reason]
|
|
43
|
-
when :ready
|
|
44
|
+
when :ready
|
|
45
|
+
waiting_on.empty? ? ["due", "due", {}] : ["waiting", "waiting_dependencies", { count: waiting_on.size }]
|
|
44
46
|
when :lagging then ["waiting", "waiting_lagging", { count: rollover[:lagging].size, revision: rollover[:revision] }]
|
|
45
47
|
when :no_workers then ["waiting", "waiting_no_workers", { revision: rollover[:revision] }]
|
|
46
48
|
else ["waiting", "waiting_no_revision", {}]
|
data/sig/pgbus/client.rbs
CHANGED
|
@@ -71,7 +71,9 @@ module Pgbus
|
|
|
71
71
|
def streams_swap_stats: () -> untyped
|
|
72
72
|
def synchronizing?: () -> bool
|
|
73
73
|
def target_queue: (untyped queue_name, ?untyped priority) -> untyped
|
|
74
|
+
def topic_patterns: (untyped queue_name) -> Array[String]
|
|
74
75
|
def transaction: () ?{ (*untyped) -> untyped } -> untyped
|
|
76
|
+
def unbind_topic: (untyped pattern, untyped queue_name) -> bool
|
|
75
77
|
def uniqueness_keys_present: (untyped lock_keys) -> untyped
|
|
76
78
|
def update_notify_insert: (untyped queue_name, throttle_interval_ms: untyped) -> untyped
|
|
77
79
|
def verify_connection!: () -> untyped
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pgbus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mikael Henriksson
|
|
@@ -285,6 +285,7 @@ files:
|
|
|
285
285
|
- lib/active_job/queue_adapters/pgbus_adapter.rb
|
|
286
286
|
- lib/generators/pgbus/add_batch_callback_jobs_generator.rb
|
|
287
287
|
- lib/generators/pgbus/add_batch_executions_generator.rb
|
|
288
|
+
- lib/generators/pgbus/add_deploy_task_run_outcomes_generator.rb
|
|
288
289
|
- lib/generators/pgbus/add_deploy_tasks_generator.rb
|
|
289
290
|
- lib/generators/pgbus/add_failed_events_index_generator.rb
|
|
290
291
|
- lib/generators/pgbus/add_failed_events_source_queue_generator.rb
|
|
@@ -308,6 +309,7 @@ files:
|
|
|
308
309
|
- lib/generators/pgbus/migration_path.rb
|
|
309
310
|
- lib/generators/pgbus/templates/add_batch_callback_jobs.rb.erb
|
|
310
311
|
- lib/generators/pgbus/templates/add_batch_executions.rb.erb
|
|
312
|
+
- lib/generators/pgbus/templates/add_deploy_task_run_outcomes.rb.erb
|
|
311
313
|
- lib/generators/pgbus/templates/add_deploy_tasks_tables.rb.erb
|
|
312
314
|
- lib/generators/pgbus/templates/add_failed_events_source_queue.rb.erb
|
|
313
315
|
- lib/generators/pgbus/templates/add_failed_events_unique_index.rb.erb
|
|
@@ -344,6 +346,7 @@ files:
|
|
|
344
346
|
- lib/pgbus/active_job/batch_id.rb
|
|
345
347
|
- lib/pgbus/active_job/current_attributes.rb
|
|
346
348
|
- lib/pgbus/active_job/delivery.rb
|
|
349
|
+
- lib/pgbus/active_job/deploy_task_run_id.rb
|
|
347
350
|
- lib/pgbus/active_job/executor.rb
|
|
348
351
|
- lib/pgbus/active_job/quiet_logs.rb
|
|
349
352
|
- lib/pgbus/autovacuum_tuning.rb
|
|
@@ -380,9 +383,11 @@ files:
|
|
|
380
383
|
- lib/pgbus/dead_letter_header.rb
|
|
381
384
|
- lib/pgbus/dedicated_connection.rb
|
|
382
385
|
- lib/pgbus/dedup_cache.rb
|
|
386
|
+
- lib/pgbus/deploy/dependencies.rb
|
|
383
387
|
- lib/pgbus/deploy/revision.rb
|
|
384
388
|
- lib/pgbus/deploy/rollover.rb
|
|
385
389
|
- lib/pgbus/deploy/runner.rb
|
|
390
|
+
- lib/pgbus/deploy/schema.rb
|
|
386
391
|
- lib/pgbus/deploy/task.rb
|
|
387
392
|
- lib/pgbus/doctor.rb
|
|
388
393
|
- lib/pgbus/engine.rb
|