Class: CommandTower::Workflows::ApplicationWorkflow
Direct Known Subclasses
CommandTower::Workflows::Admin::Messaging::CreateAnnouncementWorkflow, CommandTower::Workflows::Admin::Users::ListAssignableRolesWorkflow, CommandTower::Workflows::Admin::Users::ListWorkflow, CommandTower::Workflows::Admin::Users::SetEmailValidatedWorkflow, CommandTower::Workflows::Admin::Users::ShowWorkflow, CommandTower::Workflows::Admin::Users::UpdateEmailWorkflow, CommandTower::Workflows::Admin::Users::UpdateNameWorkflow, CommandTower::Workflows::Admin::Users::UpdateRolesWorkflow, CommandTower::Workflows::Admin::Users::UpdateUsernameWorkflow, CommandTower::Workflows::Admin::Workspace::ManifestWorkflow, CommandTower::Workflows::Audit::Events::FilterOptionsForAdminWorkflow, CommandTower::Workflows::Audit::Events::FilterOptionsForUserWorkflow, CommandTower::Workflows::Audit::Events::ListForAdminWorkflow, CommandTower::Workflows::Audit::Events::ListForUserWorkflow, CommandTower::Workflows::Audit::Events::ShowForAdminWorkflow, CommandTower::Workflows::Audit::Events::ShowForUserWorkflow, CommandTower::Workflows::Auth::AuthenticateRequestWorkflow, CommandTower::Workflows::Auth::AuthorizeRequestWorkflow, CommandTower::Workflows::Auth::EmailAvailabilityWorkflow, CommandTower::Workflows::Auth::EmailVerification::SendWorkflow, CommandTower::Workflows::Auth::EmailVerification::VerifyWorkflow, CommandTower::Workflows::Auth::IdentityPolicyWorkflow, CommandTower::Workflows::Auth::LogoutWorkflow, CommandTower::Workflows::Auth::PasswordRecoverySession::AuthenticateWorkflow, CommandTower::Workflows::Auth::PasswordRecoverySession::CreateWorkflow, CommandTower::Workflows::Auth::PasswordReset::ResetWorkflow, CommandTower::Workflows::Auth::PasswordReset::SendWorkflow, CommandTower::Workflows::Auth::PasswordReset::ValidateWorkflow, CommandTower::Workflows::Auth::PlainText::LoginWorkflow, CommandTower::Workflows::Auth::PrincipalCapabilities::ShowWorkflow, CommandTower::Workflows::Auth::RegisterWorkflow, CommandTower::Workflows::Auth::Session::ShowWorkflow, CommandTower::Workflows::Auth::SignupSession::AuthenticateWorkflow, CommandTower::Workflows::Auth::SignupSession::CreateWorkflow, CommandTower::Workflows::Auth::UsernameAvailabilityWorkflow, Impersonation::StartWorkflow, Impersonation::StopWorkflow, Me::ChangePasswordWorkflow, Me::ClearPhoneWorkflow, Me::DeleteAccountWorkflow, Me::PhoneVerification::SendWorkflow, Me::PhoneVerification::VerifyWorkflow, Me::Pushover::CreateWorkflow, Me::Pushover::DestroyWorkflow, Me::Pushover::ReplaceWorkflow, Me::Pushover::ShowWorkflow, Me::Pushover::VerifyWorkflow, Me::ShowWorkflow, Me::UpdateNameWorkflow, Me::UpdatePhoneWorkflow, Messaging::Communications::ProduceRecipientWorkflow, Messaging::Execution::DeliverWorkflow, Messaging::Handoff::ProcessWorkflow, Messaging::Inbox::BaseWorkflow, Messaging::Preferences::ShowWorkflow, Messaging::Preferences::UpdateWorkflow, Profile::ShowWorkflow
Defined Under Namespace
Classes: DelayedContinuationRequiresJob, InvalidDeferredResult
Constant Summary
collapse
- TransactionFailure =
CommandTower::Transactional::TransactionFailure
- InvalidTransactionResult =
CommandTower::Transactional::InvalidTransactionResult
- ALLOWED_RETRY_STRATEGIES =
%i[none delayed_continuation scheduled_cadence].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
included
included
#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event
#fail_transaction!, #transaction
Class Method Details
.call(**args) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 26
def call(**args)
validate_retry_strategy!
CommandTower::Events.around_execution(layer: :workflow, subject: name, log_lifecycle: lifecycle_loggable?) do |record|
begin
record[:result] = new.call(**args)
rescue TransactionFailure => e
record[:result] = e.result
rescue InvalidTransactionResult
raise
rescue StandardError => e
record[:unexpected] = e
record[:result] = WorkflowResult.failure(
errors: [CommandTower::Errors::InternalError.new(cause: e)],
http_status: :internal_server_error
)
end
mark_impersonation_activity!(record[:result])
end
end
|
.call_from_job(job: nil, continuation_attempt: 1, **args) ⇒ Object
Job transport entry. Unexpected exceptions re-raise. Deferred continuation
is scheduled by CommandTower when the strategy is :delayed_continuation.
48
49
50
51
52
53
54
55
56
57
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 48
def call_from_job(job: nil, continuation_attempt: 1, **args)
validate_retry_strategy!
result = invoke_for_job(**args)
handle_job_result(
result,
job: job,
continuation_attempt: Integer(continuation_attempt),
**args
)
end
|
.continuation_max_attempts ⇒ Object
68
69
70
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 68
def continuation_max_attempts
@continuation_max_attempts
end
|
.declared_retry_strategy ⇒ Object
64
65
66
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 64
def declared_retry_strategy
@retry_strategy
end
|
.mark_impersonation_activity!(result) ⇒ Object
72
73
74
75
76
77
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 72
def mark_impersonation_activity!(result)
return unless impersonation_activity?
return unless result.is_a?(CommandTower::Workflows::WorkflowResult) && result.success?
CommandTower::Current.impersonation_activity_recorded = true
end
|
.retry_strategy(strategy, max_attempts: nil) ⇒ Object
59
60
61
62
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 59
def retry_strategy(strategy, max_attempts: nil)
@retry_strategy = strategy&.to_sym
@continuation_max_attempts = max_attempts
end
|
.validate_retry_strategy! ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 80
def validate_retry_strategy!
raise "#{name} must declare retry_strategy (:none, :delayed_continuation, or :scheduled_cadence)" if @retry_strategy.nil?
if @retry_strategy == :sidekiq
raise "#{name} retry_strategy :sidekiq is not supported; use :delayed_continuation"
end
unless ALLOWED_RETRY_STRATEGIES.include?(@retry_strategy)
raise "#{name} retry_strategy #{@retry_strategy.inspect} is invalid " \
"(allowed: :none, :delayed_continuation, :scheduled_cadence)"
end
if @retry_strategy == :delayed_continuation
max = @continuation_max_attempts
unless max.is_a?(Integer) && max >= 1
raise "#{name} retry_strategy :delayed_continuation requires max_attempts: >= 1"
end
elsif !@continuation_max_attempts.nil?
raise "#{name} retry_strategy #{@retry_strategy.inspect} cannot declare max_attempts"
end
end
|
Instance Method Details
#call ⇒ Object
158
159
160
|
# File 'app/workflows/command_tower/workflows/application_workflow.rb', line 158
def call(**)
raise NotImplementedError
end
|