Class: Wf::CaseCommand::EnableTransitions
- Inherits:
-
Object
- Object
- Wf::CaseCommand::EnableTransitions
- Includes:
- SimpleCommand
- Defined in:
- app/models/wf/case_command/enable_transitions.rb
Instance Attribute Summary collapse
-
#wf_case ⇒ Object
readonly
Returns the value of attribute wf_case.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(wf_case) ⇒ EnableTransitions
constructor
A new instance of EnableTransitions.
Constructor Details
#initialize(wf_case) ⇒ EnableTransitions
Returns a new instance of EnableTransitions.
7 8 9 |
# File 'app/models/wf/case_command/enable_transitions.rb', line 7 def initialize(wf_case) @wf_case = wf_case end |
Instance Attribute Details
#wf_case ⇒ Object (readonly)
Returns the value of attribute wf_case.
6 7 8 |
# File 'app/models/wf/case_command/enable_transitions.rb', line 6 def wf_case @wf_case end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/wf/case_command/enable_transitions.rb', line 11 def call Wf::ApplicationRecord.transaction do wf_case.workitems.enabled.each do |workitem| workitem.update!(state: :overridden, overridden_at: Time.zone.now) unless wf_case.can_fire?(workitem.transition) end wf_case.workflow.transitions.each do |transition| next unless wf_case.can_fire?(transition) && !transition.workitems.where(case: wf_case, state: %i[enabled started]).exists? trigger_time = Time.zone.now + transition.trigger_limit.minutes if transition.trigger_limit && transition.time? workitem = wf_case.workitems.create!( workflow: wf_case.workflow, transition: transition, state: :enabled, trigger_time: trigger_time ) Wf::FireTimedWorkitemJob.set(wait: transition.trigger_limit.minutes).perform_later(workitem.id) if trigger_time SetWorkitemAssignments.call(workitem) workitem.transition.unassignment_callback.constantize.new(workitem.id).perform_now if workitem.workitem_assignments.count == 0 if sub_workflow = transition.sub_workflow sub_case = Wf::CaseCommand::New.call(sub_workflow, nil, workitem).result Wf::CaseCommand::StartCase.call(sub_case) end end end end |