class Dynflow::DelayedPlan

Attributes

execution_plan_uuid[R]
frozen[RW]
start_at[RW]
start_before[R]

Public Class Methods

new(world, execution_plan_uuid, start_at, start_before, args_serializer, frozen) click to toggle source
# File lib/dynflow/delayed_plan.rb, line 10
def initialize(world, execution_plan_uuid, start_at, start_before, args_serializer, frozen)
  @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
  @frozen              = Type! frozen, Algebrick::Types::Boolean
end
new_from_hash(world, hash, *args) click to toggle source

@api private

# File lib/dynflow/delayed_plan.rb, line 72
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,
           hash[:frozen] || false)
rescue NameError => e
  error(e.message)
end

Public Instance Methods

args() click to toggle source

Retrieves arguments from the serializer

@return [Array] array of the original arguments

# File lib/dynflow/delayed_plan.rb, line 66
def args
  @args_serializer.perform_deserialization! if @args_serializer.args.nil?
  @args_serializer.args
end
cancel() click to toggle source
# File lib/dynflow/delayed_plan.rb, line 41
def cancel
  execution_plan.root_plan_step.state = :cancelled
  execution_plan.root_plan_step.save
  execution_plan.update_state :stopped, history_notice: "Delayed task cancelled"
  @world.persistence.delete_delayed_plans(:execution_plan_uuid => @execution_plan_uuid)
  return true
end
error(message, history_entry = nil) click to toggle source
# File lib/dynflow/delayed_plan.rb, line 34
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.update_state :stopped, history_notice: history_entry
end
execute(future = Concurrent::Promises.resolvable_future) click to toggle source
# File lib/dynflow/delayed_plan.rb, line 49
def execute(future = Concurrent::Promises.resolvable_future)
  @world.execute(@execution_plan_uuid, future)
  ::Dynflow::World::Triggered[@execution_plan_uuid, future]
end
execution_plan() click to toggle source
# File lib/dynflow/delayed_plan.rb, line 19
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 23
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 30
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 54
def to_hash
  recursive_to_hash :execution_plan_uuid => @execution_plan_uuid,
                    :start_at            => @start_at,
                    :start_before        => @start_before,
                    :serialized_args     => @args_serializer.serialized_args,
                    :args_serializer     => @args_serializer.class.name,
                    :frozen              => @frozen
end