Class: Wf::CaseCommand::SweepAutomaticTransitions

Inherits:
Object
  • Object
show all
Includes:
SimpleCommand
Defined in:
app/models/wf/case_command/sweep_automatic_transitions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wf_case) ⇒ SweepAutomaticTransitions

Returns a new instance of SweepAutomaticTransitions.



7
8
9
# File 'app/models/wf/case_command/sweep_automatic_transitions.rb', line 7

def initialize(wf_case)
  @wf_case = wf_case
end

Instance Attribute Details

#wf_caseObject (readonly)

Returns the value of attribute wf_case.



6
7
8
# File 'app/models/wf/case_command/sweep_automatic_transitions.rb', line 6

def wf_case
  @wf_case
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/wf/case_command/sweep_automatic_transitions.rb', line 11

def call
  Wf::ApplicationRecord.transaction do
    EnableTransitions.call(wf_case)
    done = false
    until done
      done = true
      finished = FinishedP.call(wf_case).result
      next if finished

      Wf::ApplicationRecord.uncached do
        wf_case.workitems.joins(:transition).where(state: :enabled).where(Wf::Transition.table_name => { trigger_type: Wf::Transition.trigger_types[:automatic] }).find_each do |item|
          FireTransitionInternal.call(item)
          done = false
        end
      end
      EnableTransitions.call(wf_case)
    end
  end
end