Skip to content

A platform for community discussion. Free, open, simple.

DEV: Reduce repetition with shorthand workflow hashes (#43727)

Régis Hanola8b749f029c2
diff --git a/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb b/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb
index 35470c57e1f..0f5d9d89ffd 100644
--- a/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb
+++ b/plugins/discourse-workflows/app/models/discourse_workflows/execution.rb
@@ -22,7 +22,7 @@ module DiscourseWorkflows
after_create { ExecutionStat.log(workflow_id) unless rate_limited? }
- scope :for_workflow, ->(workflow_id) { workflow_id ? where(workflow_id: workflow_id) : all }
+ scope :for_workflow, ->(workflow_id) { workflow_id ? where(workflow_id:) : all }
scope :recent, ->(period = 7.days) { where("created_at >= ?", period.ago) }
scope :successful, -> { where(status: :success) }
scope :with_duration,
@@ -41,15 +41,15 @@ module DiscourseWorkflows
def self.create_pending_manual!(workflow:, trigger_node_id:, trigger_data:)
transaction do
create!(
- workflow: workflow,
+ workflow:,
workflow_version_id: workflow.version_id,
- trigger_node_id: trigger_node_id,
- trigger_data: trigger_data,
+ trigger_node_id:,
+ trigger_data:,
status: :pending,
execution_mode: :manual,
).tap do |execution|
ExecutionData.create!(
- execution: execution,
+ execution:,
workflow_data: WorkflowSnapshot.from_workflow(workflow, published: false).to_h,
)
end
@@ -61,15 +61,15 @@ module DiscourseWorkflows
def self.create_pending_step!(workflow:, node_id:, trigger_data: {}, run_data: {})
transaction do
create!(
- workflow: workflow,
+ workflow:,
workflow_version_id: workflow.version_id,
trigger_node_id: node_id,
- trigger_data: trigger_data,
+ trigger_data:,
status: :pending,
execution_mode: :manual,
).tap do |execution|
ExecutionData.create!(
- execution: execution,
+ execution:,
workflow_data: WorkflowSnapshot.from_workflow(workflow, published: false).to_h,
data: {
"entries" => {
@@ -109,7 +109,7 @@ module DiscourseWorkflows
end
def self.claim_for_resume(execution, resume_token: execution.resume_token)
- scope = where(id: execution.id, status: :waiting, resume_token: resume_token)
+ scope = where(id: execution.id, status: :waiting, resume_token:)
now = Time.current
affected = scope.update_all(status: statuses[:running], updated_at: now)
@@ -168,18 +168,12 @@ module DiscourseWorkflows
affected =
self
.class
- .where(
- id: id,
- status: :waiting,
- resume_token: resume_token,
- waiting_until: waiting_until,
- timeout_action: timeout_action,
- )
+ .where(id:, status: :waiting, resume_token:, waiting_until:, timeout_action:)
.update_all(
status: self.class.statuses[:error],
error: message,
finished_at: Time.current,
- run_time_ms: run_time_ms,
+ run_time_ms:,
waiting_node_id: nil,
waiting_until: nil,
resume_token: nil,
diff --git a/plugins/discourse-workflows/app/services/discourse_workflows/webhook/receive.rb b/plugins/discourse-workflows/app/services/discourse_workflows/webhook/receive.rb
index f1e90e08f66..631792b3f3c 100644
--- a/plugins/discourse-workflows/app/services/discourse_workflows/webhook/receive.rb
+++ b/plugins/discourse-workflows/app/services/discourse_workflows/webhook/receive.rb
@@ -28,7 +28,7 @@ module DiscourseWorkflows
def webhook_url
if execution_id.present?
DiscourseWorkflows::WaitingExecution.webhook_url_with_signature(
- execution_id: execution_id,
+ execution_id:,
signature: token,
suffix: webhook_suffix,
)
@@ -43,15 +43,15 @@ module DiscourseWorkflows
def webhook_request
DiscourseWorkflows::WebhookRequest.new(
method: http_method,
- path: path,
- headers: headers,
+ path:,
+ headers:,
params: path_params,
query: query_params,
- body: body,
- raw_body: raw_body,
+ body:,
+ raw_body:,
ip: remote_ip,
- ips: ips,
- webhook_url: webhook_url,
+ ips:,
+ webhook_url:,
)
end
end
@@ -160,7 +160,7 @@ module DiscourseWorkflows
return [] unless workflow
return [] unless trigger_node
- [PublishedTrigger.new(workflow: workflow, workflow_version: nil, trigger_node: trigger_node)]
+ [PublishedTrigger.new(workflow:, workflow_version: nil, trigger_node:)]
end
def fetch_waiting_node(waiting_execution:)
@@ -201,15 +201,15 @@ module DiscourseWorkflows
DiscourseWorkflows::WaitingExecution.resume_claimed(
claimed_execution,
webhook_context.resume_items,
- webhook_context: webhook_context,
+ webhook_context:,
)
{
- execution: execution,
+ execution:,
response_mode: parameters["response_mode"],
response_code: parameters["response_code"],
response_data: parameters["response_data"],
response_parameters: parameters,
- webhook_context: webhook_context,
+ webhook_context:,
}
end
@@ -240,11 +240,7 @@ module DiscourseWorkflows
node = workflow_version.nodes.find { |candidate| candidate["name"] == webhook.node_name }
return nil unless node
- PublishedTrigger.new(
- workflow: workflow,
- workflow_version: workflow_version,
- trigger_node: node,
- )
+ PublishedTrigger.new(workflow:, workflow_version:, trigger_node: node)
end
def filter_authenticated_nodes(webhook_nodes:, params:)
@@ -256,8 +252,8 @@ module DiscourseWorkflows
result =
Webhook::Action::AuthenticateNode.call(
node: published_trigger.trigger_node,
- params: params,
- credentials: credentials,
+ params:,
+ credentials:,
)
if result == Webhook::Action::AuthenticateNode::AUTHENTICATED
@@ -332,15 +328,15 @@ module DiscourseWorkflows
DiscourseWorkflows::TriggerDispatcher.execute(
published_trigger,
trigger_data: webhook_context.request.item_json,
- webhook_context: webhook_context,
+ webhook_context:,
)
first ||= {
- execution: execution,
- response_mode: response_mode,
+ execution:,
+ response_mode:,
response_code: parameters["response_code"],
response_data: parameters["response_data"],
response_parameters: parameters,
- webhook_context: webhook_context,
+ webhook_context:,
}
end
first
@@ -360,7 +356,7 @@ module DiscourseWorkflows
execution_mode: :manual,
draft_execution: true,
workflow_snapshot: claimed_webhook_test_listener.workflow_snapshot,
- webhook_context: webhook_context,
+ webhook_context:,
)
execution =
Executor.new(
@@ -371,12 +367,12 @@ module DiscourseWorkflows
).run
{
- execution: execution,
+ execution:,
response_mode: node_response_mode(node),
response_code: parameters["response_code"],
response_data: parameters["response_data"],
response_parameters: parameters,
- webhook_context: webhook_context,
+ webhook_context:,
}
end
diff --git a/plugins/discourse-workflows/app/services/discourse_workflows/workflow/execute.rb b/plugins/discourse-workflows/app/services/discourse_workflows/workflow/execute.rb
index c8b95261a08..dca004b7ff2 100644
--- a/plugins/discourse-workflows/app/services/discourse_workflows/workflow/execute.rb
+++ b/plugins/discourse-workflows/app/services/discourse_workflows/workflow/execute.rb
@@ -61,9 +61,9 @@ module DiscourseWorkflows
def run_workflow(trigger_node:, workflow:, workflow_version:, params:, user:)
options =
Executor::ExecutionOptions.new(
- user: user,
+ user:,
execution_mode: params.execution_mode.to_sym,
- workflow_version: workflow_version,
+ workflow_version:,
job_id: params.job_id,
)
Executor.new(workflow, trigger_node["id"], params.trigger_data, options).run
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/executor.rb b/plugins/discourse-workflows/lib/discourse_workflows/executor.rb
index cc0b7c77c3e..672132a3b23 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/executor.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/executor.rb
@@ -45,7 +45,7 @@ module DiscourseWorkflows
workflow: @workflow,
trigger_data: @trigger_data,
user: @options.user,
- workflow_nodes: workflow_nodes,
+ workflow_nodes:,
workflow_name: workflow_version&.name,
workflow_call_caller: @options.workflow_call_caller,
)
@@ -66,27 +66,27 @@ module DiscourseWorkflows
end
def self.resume(execution, response_items, user: nil, webhook_context: nil)
- build_resume_executor(execution, user: user, webhook_context: webhook_context).resume_from(
+ build_resume_executor(execution, user:, webhook_context:).resume_from(
execution,
response_items,
)
end
def self.resume_with_error(execution, error, user: nil)
- build_resume_executor(execution, user: user).resume_from_error(execution, error)
+ build_resume_executor(execution, user:).resume_from_error(execution, error)
end
def self.build_resume_executor(execution, user:, webhook_context: nil)
workflow_call_caller = WorkflowCallContinuation.caller_metadata_for(execution)
options =
ExecutionOptions.new(
- user: user,
+ user:,
execution_mode: execution.execution_mode.to_sym,
workflow_snapshot: build_resume_snapshot!(execution),
- webhook_context: webhook_context,
+ webhook_context:,
workflow_call_stack: WorkflowCallContinuation.workflow_call_stack_for(execution),
workflow_call_child: workflow_call_caller.present?,
- workflow_call_caller: workflow_call_caller,
+ workflow_call_caller:,
)
new(execution.workflow, execution.trigger_node_id, execution.trigger_data, options)
end
@@ -164,7 +164,7 @@ module DiscourseWorkflows
step&.add_metadata("handled_error", error_metadata(error))
step&.succeed!(output: all_items)
step&.apply_updates!("error" => nil)
- @store.publish_progress(step: step) if step
+ @store.publish_progress(step:) if step
@context.store_node_output(waiting_node, all_items)
@context.store_node_run(
waiting_node,
@@ -176,7 +176,7 @@ module DiscourseWorkflows
route_downstream(waiting_node, handled_outputs)
else
step&.fail!(error.message)
- @store.publish_progress(step: step) if step
+ @store.publish_progress(step:) if step
raise error
end
end
@@ -214,7 +214,7 @@ module DiscourseWorkflows
step = record_step(node, [])
step.succeed!(output: output_groups.flatten(1))
step.add_metadata("cached", true)
- @store.publish_progress(step: step)
+ @store.publish_progress(step:)
route_downstream(node, output_groups)
end
@@ -436,7 +436,7 @@ module DiscourseWorkflows
js_elapsed = (sandbox_budget_tracker.current_elapsed_ms - js_elapsed_before).round(1)
step.add_metadata("js_elapsed_ms", js_elapsed) if js_elapsed > 0
runtime_state.step_metadata.each { |key, value| step.add_metadata(key, value) }
- @store.publish_progress(step: step)
+ @store.publish_progress(step:)
end
end
@@ -460,7 +460,7 @@ module DiscourseWorkflows
step.add_metadata(
DiscourseWorkflows::FormCompletion::METADATA_KEY,
- DiscourseWorkflows::FormCompletion.for_node(node, resolver: resolver),
+ DiscourseWorkflows::FormCompletion.for_node(node, resolver:),
)
end
@@ -479,8 +479,8 @@ module DiscourseWorkflows
"in workflow #{@context.workflow.id}, passing through node '#{node.name}'",
)
step = record_step(node, input_items)
- step.skip!(output: input_items, reason: reason)
- @store.publish_progress(step: step)
+ step.skip!(output: input_items, reason:)
+ @store.publish_progress(step:)
@context.store_node_output(node, input_items)
@context.store_node_run(node, inputs: [input_items], outputs: [input_items])
enqueue_downstream(node, 0, input_items)
@@ -489,8 +489,8 @@ module DiscourseWorkflows
def handle_node_issues(node, input_items, issues)
reason = issues.map { |i| "#{i[:path]}: #{i[:message]}" }.join(", ")
step = record_step(node, input_items)
- step.skip!(output: input_items, reason: reason)
- @store.publish_progress(step: step)
+ step.skip!(output: input_items, reason:)
+ @store.publish_progress(step:)
@context.store_node_output(node, input_items)
@context.store_node_run(node, inputs: [input_items], outputs: [input_items])
enqueue_downstream(node, 0, input_items)
@@ -500,7 +500,7 @@ module DiscourseWorkflows
step = record_step(node, input_items)
step.succeed!(output: pinned_items)
step.add_metadata("pinned", true)
- @store.publish_progress(step: step)
+ @store.publish_progress(step:)
@context.store_node_output(node, pinned_items)
@context.store_node_run(
node,
@@ -557,16 +557,16 @@ module DiscourseWorkflows
)
NodeExecutionContext.new(
input_items: primary_input_items(input_groups),
- input_groups: input_groups,
+ input_groups:,
parameters: node.parameters,
credentials: node.credentials,
node_settings: DiscourseWorkflows::NodeData.direct_settings(node),
webhook_id: node.webhook_id,
property_schema: node_type_class.property_schema,
credential_schema: node_type_class.credentials,
- node_context: node_context,
+ node_context:,
user: @options.user,
- resolver: resolver,
+ resolver:,
vars: preloaded_vars,
workflow: @workflow,
workflow_version: @options.workflow_version,
@@ -582,17 +582,17 @@ module DiscourseWorkflows
workflow_snapshot: @snapshot,
webhook_context: @options.webhook_context,
workflow_call_stack: @workflow_call_stack,
- runtime_state: runtime_state,
+ runtime_state:,
static_data_state: @context.static_data_state,
)
end
def normalize_result(result, node, ports, input_groups)
source = "#{node.name} (#{node.type})"
- ItemContract.validate_output_arrays!(result, source: source, ports: ports)
+ ItemContract.validate_output_arrays!(result, source:, ports:)
apply_item_linking_defaults!(result, input_groups:)
- ItemContract.validate_output_arrays!(result, source: source, ports: ports)
+ ItemContract.validate_output_arrays!(result, source:, ports:)
result
end
@@ -857,20 +857,14 @@ module DiscourseWorkflows
if explicit_required_inputs.is_a?(Integer)
{
- connected_inputs: connected_inputs,
+ connected_inputs:,
inputs_to_wait_for: [],
minimum_input_count: explicit_required_inputs,
}
elsif explicit_required_inputs.present?
- {
- connected_inputs: connected_inputs,
- inputs_to_wait_for: Array(explicit_required_inputs).map(&:to_i),
- }
+ { connected_inputs:, inputs_to_wait_for: Array(explicit_required_inputs).map(&:to_i) }
else
- {
- connected_inputs: connected_inputs,
- inputs_to_wait_for: (required_inputs + connected_inputs).uniq,
- }
+ { connected_inputs:, inputs_to_wait_for: (required_inputs + connected_inputs).uniq }
end
end
end
@@ -900,17 +894,9 @@ module DiscourseWorkflows
end
def record_step(node, input_items, output: [], status: Step::RUNNING, error: nil)
- step =
- Step.build(
- node: node,
- position: @steps.size,
- input: input_items,
- output: output,
- status: status,
- error: error,
- )
+ step = Step.build(node:, position: @steps.size, input: input_items, output:, status:, error:)
@steps << step
- @store.publish_progress(step: step)
+ @store.publish_progress(step:)
step
end
@@ -928,7 +914,7 @@ module DiscourseWorkflows
"output" => response_items,
"finished_at" => Time.current.iso8601,
)
- @store.publish_progress(step: step)
+ @store.publish_progress(step:)
end
def begin_wait!(wait_request)
@@ -959,7 +945,7 @@ module DiscourseWorkflows
@store.pause_waiting_execution!(
node: @waiting_node,
waiting_until: resolved,
- timeout_action: timeout_action,
+ timeout_action:,
steps: @steps,
)
@@ -976,7 +962,7 @@ module DiscourseWorkflows
execution = @store.pause_waiting_execution!(node: @waiting_node, steps: @steps)
DiscourseWorkflows::WorkflowCallContinuation.begin_child_call!(
- execution: execution,
+ execution:,
node: @waiting_node,
request: wait_request,
)
@@ -1141,11 +1127,7 @@ module DiscourseWorkflows
def node_dependencies(node)
parameters = NodeData.parameters(node)
credentials =
- NodeData.split(
- parameters: parameters,
- credentials: NodeData.credentials(node),
- node_type: node.type,
- )[
+ NodeData.split(parameters:, credentials: NodeData.credentials(node), node_type: node.type)[
"credentials"
]
dependencies = []
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb b/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb
index 84814a3ae27..00e713da917 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb
@@ -37,7 +37,7 @@ module DiscourseWorkflows
@workflow_snapshot.to_h["nodes"],
workflow_name: @workflow_snapshot.workflow_name,
)
- persist_execution!(status: :running, trigger_data: trigger_data)
+ persist_execution!(status: :running, trigger_data:)
return false if @duplicate_job
reset_collaborators!
@@ -95,7 +95,7 @@ module DiscourseWorkflows
waiting_until: nil,
timeout_action: nil,
)
- execution.trigger_error_workflow(error, steps: steps)
+ execution.trigger_error_workflow(error, steps:)
publish_execution_run_data(
force: @options.draft_execution || @options.workflow_snapshot.present?,
)
@@ -107,7 +107,7 @@ module DiscourseWorkflows
end
def create_execution_with_status(status, trigger_data: self.trigger_data)
- persist_execution!(status: status, trigger_data: trigger_data, finished_at: Time.current)
+ persist_execution!(status:, trigger_data:, finished_at: Time.current)
end
def create_rate_limited_execution
@@ -119,9 +119,9 @@ module DiscourseWorkflows
execution.update!(
status: :waiting,
waiting_node_id: node.id,
- waiting_until: waiting_until,
+ waiting_until:,
resume_token: @execution_context.resume_token,
- timeout_action: timeout_action,
+ timeout_action:,
)
save!(steps)
end
@@ -142,7 +142,7 @@ module DiscourseWorkflows
end
def publish_progress(step: nil, refresh: false)
- ExecutionProgressPublisher.publish(execution, step: step, refresh: refresh)
+ ExecutionProgressPublisher.publish(execution, step:, refresh:)
end
private
@@ -155,11 +155,11 @@ module DiscourseWorkflows
workflow_id: workflow.id,
workflow_version_id: execution_workflow_version_id,
trigger_node_id: @trigger_node_id,
- status: status,
- trigger_data: trigger_data,
+ status:,
+ trigger_data:,
execution_mode: @execution_mode,
started_at: @execution.started_at || Time.current,
- finished_at: finished_at,
+ finished_at:,
}
if @options.job_id.present?
diff --git a/plugins/discourse-workflows/spec/integration/execution_lifecycle_spec.rb b/plugins/discourse-workflows/spec/integration/execution_lifecycle_spec.rb
index aaeea3529e3..a7f0b54a59f 100644
--- a/plugins/discourse-workflows/spec/integration/execution_lifecycle_spec.rb
+++ b/plugins/discourse-workflows/spec/integration/execution_lifecycle_spec.rb
@@ -46,7 +46,7 @@ RSpec.describe "Workflow execution lifecycle" do
stub_request(:get, checkpoint_url).to_raise(Sidekiq::Shutdown).then.to_return(http_success)
execution =
DiscourseWorkflows::Execution.create_pending_manual!(
- workflow: workflow,
+ workflow:,
trigger_node_id: "trigger-1",
trigger_data: {
},
diff --git a/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_waiting_execution_spec.rb b/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_waiting_execution_spec.rb
index 8019dfde81e..9e80b71afc7 100644
--- a/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_waiting_execution_spec.rb
+++ b/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_waiting_execution_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Jobs::DiscourseWorkflows::ResumeWaitingExecution do
fab!(:execution) do
Fabricate(
:discourse_workflows_execution,
- workflow: workflow,
+ workflow:,
status: :waiting,
waiting_until: 1.minute.ago,
resume_token: "wait-token",
diff --git a/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_webhook_waiting_spec.rb b/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_webhook_waiting_spec.rb
index 282b1ad1604..7646fdd8004 100644
--- a/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_webhook_waiting_spec.rb
+++ b/plugins/discourse-workflows/spec/jobs/regular/discourse_workflows/resume_webhook_waiting_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Jobs::DiscourseWorkflows::ResumeWebhookWaiting do
fab!(:execution) do
Fabricate(
:discourse_workflows_execution,
- workflow: workflow,
+ workflow:,
status: :waiting,
resume_token: "wait-token",
)
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/execution_store_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/execution_store_spec.rb
index d088fab78cc..4d33ec0725d 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/execution_store_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/execution_store_spec.rb
@@ -5,19 +5,15 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
let(:trigger_data) { { "topic_id" => 1 } }
let(:execution_context) do
- DiscourseWorkflows::Executor::ExecutionContext.new(
- workflow: workflow,
- trigger_data: trigger_data,
- user: nil,
- )
+ DiscourseWorkflows::Executor::ExecutionContext.new(workflow:, trigger_data:, user: nil)
end
let(:options) { DiscourseWorkflows::Executor::ExecutionOptions.new }
let(:store) do
described_class.new(
trigger_node_id: "node_1",
- execution_context: execution_context,
+ execution_context:,
execution_mode: :normal,
- options: options,
+ options:,
)
end
@@ -44,7 +40,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
messages =
MessageBus.track_publish("/discourse-workflows/execution/#{execution.id}") do
- store.publish_progress(step: step)
+ store.publish_progress(step:)
end
expect(messages.length).to eq(1)
@@ -92,7 +88,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
),
]
- store.finish!(steps: steps)
+ store.finish!(steps:)
parsed = store.execution.execution_data.data
expect(parsed["context"]["node_a"]).to eq([{ "json" => { "x" => 1 } }])
@@ -111,7 +107,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
)
steps = [
DiscourseWorkflows::Executor::Step.build(
- node: node,
+ node:,
position: 0,
input: input_groups.first,
status: DiscourseWorkflows::Executor::Step::SUCCESS,
@@ -121,7 +117,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
messages =
MessageBus.track_publish("/discourse-workflows/workflow/#{workflow.id}") do
- store.finish!(steps: steps)
+ store.finish!(steps:)
end
expect(messages.length).to eq(1)
@@ -160,7 +156,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
),
]
- store.finish!(steps: steps)
+ store.finish!(steps:)
entry = store.execution.execution_data.data.dig("entries", "1", 0)
expect(entry.dig("input", 0, "json", "body")).to include(
@@ -192,7 +188,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
),
]
- store.finish!(steps: steps)
+ store.finish!(steps:)
entry = store.execution.execution_data.data.dig("entries", "1", 0)
expect(entry["input"]).to include(
@@ -230,7 +226,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
)
end
- store.finish!(steps: steps)
+ store.finish!(steps:)
data = store.execution.execution_data.data
entry = data.dig("entries", "node-0", 0)
@@ -257,11 +253,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
it "persists the requested timeout action" do
waiting_until = 15.minutes.from_now
- store.pause_waiting_execution!(
- node: node,
- waiting_until: waiting_until,
- timeout_action: "fail",
- )
+ store.pause_waiting_execution!(node:, waiting_until:, timeout_action: "fail")
expect(store.execution.reload).to have_attributes(
status: "waiting",
@@ -272,7 +264,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
end
it "keeps timeout action nil when existing callers omit it" do
- store.pause_waiting_execution!(node: node)
+ store.pause_waiting_execution!(node:)
expect(store.execution.reload.timeout_action).to be_nil
end
@@ -282,7 +274,7 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
interrupt_checkpoint = -> { raise Sidekiq::Shutdown }
DiscourseWorkflows::ExecutionData.set_callback(:save, :before, interrupt_checkpoint)
- expect { store.pause_waiting_execution!(node: node) }.to raise_error(Sidekiq::Shutdown)
+ expect { store.pause_waiting_execution!(node:) }.to raise_error(Sidekiq::Shutdown)
expect(store.execution.reload).to have_attributes(status: "running", waiting_node_id: nil)
expect(store.execution.execution_data).to be_nil
@@ -376,31 +368,27 @@ RSpec.describe DiscourseWorkflows::Executor::ExecutionStore do
)
steps = [
DiscourseWorkflows::Executor::Step.build(
- node: node,
+ node:,
position: 0,
input: [],
status: DiscourseWorkflows::Executor::Step::WAITING,
output: output_groups.first,
),
]
- store.finish!(steps: steps)
+ store.finish!(steps:)
existing_data = store.execution.execution_data.data.deep_dup
existing_data["node_contexts"] = { "node_a" => { "counter" => 1 } }
store.execution.execution_data.update!(data: existing_data)
store.execution.update!(status: :waiting, waiting_node_id: "1")
restored_context =
- DiscourseWorkflows::Executor::ExecutionContext.new(
- workflow: workflow,
- trigger_data: trigger_data,
- user: nil,
- )
+ DiscourseWorkflows::Executor::ExecutionContext.new(workflow:, trigger_data:, user: nil)
restored =
described_class.new(
trigger_node_id: "node_1",
execution_context: restored_context,
execution_mode: :normal,
- options: options,
+ options:,
)
restored.resume!(store.execution)
diff --git a/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb b/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb
index 2efd862af69..3a766f50f72 100644
--- a/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb
+++ b/plugins/discourse-workflows/spec/models/discourse_workflows/execution_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe DiscourseWorkflows::Execution do
fab!(:execution) do
Fabricate(
:discourse_workflows_execution,
- workflow: workflow,
+ workflow:,
status: :waiting,
resume_token: "tok-abc",
)
@@ -36,9 +36,7 @@ RSpec.describe DiscourseWorkflows::Execution do
describe ".claim_pending" do
fab!(:workflow, :discourse_workflows_workflow)
- fab!(:execution) do
- Fabricate(:discourse_workflows_execution, workflow: workflow, status: :pending)
- end
+ fab!(:execution) { Fabricate(:discourse_workflows_execution, workflow:, status: :pending) }
it "starts a pending execution once" do
claimed = described_class.claim_pending(execution)
@@ -56,7 +54,7 @@ RSpec.describe DiscourseWorkflows::Execution do
fab!(:execution) do
Fabricate(
:discourse_workflows_execution,
- workflow: workflow,
+ workflow:,
status: :waiting,
waiting_node_id: "node-1",
waiting_until: 1.minute.ago,
@@ -134,11 +132,11 @@ RSpec.describe DiscourseWorkflows::Execution do
def build_step(node_type: "action:code", started_at: nil, finished_at: nil)
node = Struct.new(:id, :name, :type).new(SecureRandom.uuid, "Node", node_type)
DiscourseWorkflows::Executor::Step.build(
- node: node,
+ node:,
position: 0,
input: [],
- started_at: started_at,
- finished_at: finished_at,
+ started_at:,
+ finished_at:,
)
end
@@ -203,9 +201,9 @@ RSpec.describe DiscourseWorkflows::Execution do
before { SiteSetting.workflow_executions_retention_days = 30 }
def fabricate_at(status, created_at)
- execution = Fabricate(:discourse_workflows_execution, workflow: workflow, status: status)
- Fabricate(:discourse_workflows_execution_data, execution: execution)
- described_class.where(id: execution.id).update_all(created_at: created_at)
+ execution = Fabricate(:discourse_workflows_execution, workflow:, status:)
+ Fabricate(:discourse_workflows_execution_data, execution:)
+ described_class.where(id: execution.id).update_all(created_at:)
execution
end
@@ -257,7 +255,7 @@ RSpec.describe DiscourseWorkflows::Execution do
described_class.purge_old
- expect(described_class.where(workflow: workflow, status: :success)).to be_empty
+ expect(described_class.where(workflow:, status: :success)).to be_empty
end
end
end
diff --git a/plugins/discourse-workflows/spec/services/discourse_workflows/webhook/receive_spec.rb b/plugins/discourse-workflows/spec/services/discourse_workflows/webhook/receive_spec.rb
index 98d01e73336..e4bf45247e2 100644
--- a/plugins/discourse-workflows/spec/services/discourse_workflows/webhook/receive_spec.rb
+++ b/plugins/discourse-workflows/spec/services/discourse_workflows/webhook/receive_spec.rb
@@ -76,7 +76,7 @@ RSpec.describe DiscourseWorkflows::Webhook::Receive do
let(:signature) do
DiscourseWorkflows::WaitingExecution.resume_signature(
execution_id: waiting_execution.id,
- resume_token: resume_token,
+ resume_token:,
)
end
@@ -84,7 +84,7 @@ RSpec.describe DiscourseWorkflows::Webhook::Receive do
{
execution_id: waiting_execution.id,
token: signature,
- webhook_suffix: webhook_suffix,
+ webhook_suffix:,
http_method: "POST",
body: {
"foo" => "bar",
@@ -120,7 +120,7 @@ RSpec.describe DiscourseWorkflows::Webhook::Receive do
"webhook_url" =>
DiscourseWorkflows::WaitingExecution.webhook_url(
execution_id: waiting_execution.id,
- resume_token: resume_token,
+ resume_token:,
),
)
end
@@ -152,8 +152,8 @@ RSpec.describe DiscourseWorkflows::Webhook::Receive do
expect(result).to run_successfully
expect(result[:sync_result]).to include(
execution: waiting_execution,
- response_mode: response_mode,
- response_code: response_code,
+ response_mode:,
+ response_code:,
)
expect(waiting_execution.reload).to be_success
end
@@ -329,10 +329,7 @@ RSpec.describe DiscourseWorkflows::Webhook::Receive do
it "returns a synchronous result without enqueuing a job" do
expect(result).to run_successfully
expect(Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs).to be_empty
- expect(result[:sync_result]).to include(
- response_mode: "last_node",
- response_code: response_code,
- )
+ expect(result[:sync_result]).to include(response_mode: "last_node", response_code:)
expect(result[:sync_result][:execution]).to have_attributes(
workflow_id: workflow.id,
status: "success",
@@ -343,10 +340,10 @@ RSpec.describe DiscourseWorkflows::Webhook::Receive do
context "when triggering a test webhook" do
let(:test_listener_id) { nil }
- let(:params) { super().merge(test_webhook: true, test_listener_id: test_listener_id) }
+ let(:params) { super().merge(test_webhook: true, test_listener_id:) }
let(:listener) do
DiscourseWorkflows::WebhookTestListener.create!(
- workflow: workflow,
+ workflow:,
user: admin,
trigger_node: workflow.find_node("webhook-1"),
)