class Dynflow::DelayedPlan

Attributes

execution_plan_uuid[R]
start_at[R]
start_before[R]

Public Class Methods

new(world, execution_plan_uuid, start_at, start_before, args_serializer) click to toggle source
# File lib/dynflow/delayed_plan.rb, line 8
def initialize(world, execution_plan_uuid, start_at, start_before, args_serializer)
  @world               = Type! world, World
  @execution_plan_uuid = Type! execution_plan_uuid, String
  @start_at            = Type! start_at, Time, NilClass
  @start_before        = Type! start_before, Time, NilClass
  @args_serializer     = Type! args_serializer, Serializers::Abstract
end
new_from_hash(world, hash, *args) click to toggle source

@api private

# File lib/dynflow/delayed_plan.rb, line 59
def self.new_from_hash(world, hash, *args)
  serializer = Utils.constantize(hash[:args_serializer]).new(nil, hash[:serialized_args])
  self.new(world,
           hash[:execution_plan_uuid],
           string_to_time(hash[:start_at]),
           string_to_time(hash[:start_before]),
           serializer)
rescue NameError => e
  error(e.message)
end

Public Instance Methods

cancel() click to toggle source
# File lib/dynflow/delayed_plan.rb, line 39
def cancel
  error("Delayed task cancelled", "Delayed task cancelled")
  @world.persistence.delete_delayed_plans(:execution_plan_uuid => execution_plan.id)
  return true
end
error(message, history_entry = nil) click to toggle source
# File lib/dynflow/delayed_plan.rb, line 31
def error(message, history_entry = nil)
  execution_plan.root_plan_step.state = :error
  execution_plan.root_plan_step.error = ::Dynflow::ExecutionPlan::Steps::Error.new(message)
  execution_plan.root_plan_step.save
  execution_plan.execution_history.add history_entry, @world.id unless history_entry.nil?
  execution_plan.update_state :stopped
end
execute(future = Concurrent.future) click to toggle source
# File lib/dynflow/delayed_plan.rb, line 45
def execute(future = Concurrent.future)
  @world.execute(execution_plan.id, future)
  ::Dynflow::World::Triggered[execution_plan.id, future]
end
execution_plan() click to toggle source
# File lib/dynflow/delayed_plan.rb, line 16
def execution_plan
  @execution_plan ||= @world.persistence.load_execution_plan(@execution_plan_uuid)
end
plan() click to toggle source
# File lib/dynflow/delayed_plan.rb, line 20
def plan
  execution_plan.root_plan_step.load_action
  execution_plan.generate_action_id
  execution_plan.generate_step_id
  execution_plan.plan(*@args_serializer.perform_deserialization!)
end
timeout() click to toggle source
# File lib/dynflow/delayed_plan.rb, line 27
def timeout
  error("Execution plan could not be started before set time (#{@start_before})", 'timeout')
end
to_hash() click to toggle source
# File lib/dynflow/delayed_plan.rb, line 50
def to_hash
   recursive_to_hash :execution_plan_uuid => @execution_plan_uuid,
                     :start_at            => time_to_str(@start_at),
                     :start_before        => time_to_str(@start_before),
                     :serialized_args     => @args_serializer.serialized_args,
                     :args_serializer     => @args_serializer.class.name
end