class Dynflow::Persistence

Attributes

adapter[R]

Public Class Methods

new(world, persistence_adapter, options = {}) click to toggle source
# File lib/dynflow/persistence.rb, line 12
def initialize(world, persistence_adapter, options = {})
  @world   = world
  @adapter = persistence_adapter
  @adapter.register_world(world)
  @backup_deleted_plans = options.fetch(:backup_deleted_plans, false)
  @backup_dir = options.fetch(:backup_dir, './backup')
end

Public Instance Methods

current_backup_dir() click to toggle source
# File lib/dynflow/persistence.rb, line 64
def current_backup_dir
  @backup_deleted_plans ? File.join(@backup_dir, Date.today.strftime('%Y%m%d')) : nil
end
delete_delayed_plans(filters, batch_size = 1000) click to toggle source
# File lib/dynflow/persistence.rb, line 89
def delete_delayed_plans(filters, batch_size = 1000)
  adapter.delete_delayed_plans(filters, batch_size)
end
delete_execution_plans(filters, batch_size = 1000, enforce_backup_dir = nil) click to toggle source
# File lib/dynflow/persistence.rb, line 59
def delete_execution_plans(filters, batch_size = 1000, enforce_backup_dir = nil)
  backup_dir = enforce_backup_dir || current_backup_dir
  adapter.delete_execution_plans(filters, batch_size, backup_dir)
end
find_execution_plan_counts(options) click to toggle source
# File lib/dynflow/persistence.rb, line 55
def find_execution_plan_counts(options)
  adapter.find_execution_plan_counts(options)
end
find_execution_plans(options) click to toggle source
# File lib/dynflow/persistence.rb, line 49
def find_execution_plans(options)
  adapter.find_execution_plans(options).map do |execution_plan_hash|
    ExecutionPlan.new_from_hash(execution_plan_hash, @world)
  end
end
find_old_execution_plans(age) click to toggle source
# File lib/dynflow/persistence.rb, line 77
def find_old_execution_plans(age)
  adapter.find_old_execution_plans(age).map do |plan|
    ExecutionPlan.new_from_hash(plan, @world)
  end
end
find_past_delayed_plans(time) click to toggle source
# File lib/dynflow/persistence.rb, line 83
def find_past_delayed_plans(time)
  adapter.find_past_delayed_plans(time).map do |plan|
    DelayedPlan.new_from_hash(@world, plan)
  end
end
load_action(step) click to toggle source
# File lib/dynflow/persistence.rb, line 20
def load_action(step)
  attributes = adapter.
      load_action(step.execution_plan_id, step.action_id).
      update(step: step, phase: step.phase)
  return Action.from_hash(attributes, step.world)
end
load_action_for_presentation(execution_plan, action_id, step = nil) click to toggle source
# File lib/dynflow/persistence.rb, line 34
def load_action_for_presentation(execution_plan, action_id, step = nil)
  attributes = adapter.load_action(execution_plan.id, action_id)
  Action.from_hash(attributes.update(phase: Action::Present, execution_plan: execution_plan, step: step), @world).tap do |present_action|
    @world.middleware.execute(:present, present_action) {}
  end
end
load_actions(execution_plan, action_ids) click to toggle source
# File lib/dynflow/persistence.rb, line 27
def load_actions(execution_plan, action_ids)
  attributes = adapter.load_actions(execution_plan.id, action_ids)
  attributes.map do |action|
    Action.from_hash(action.merge(phase: Action::Present, execution_plan: execution_plan), @world)
  end
end
load_actions_attributes(execution_plan_id, attributes) click to toggle source
# File lib/dynflow/persistence.rb, line 41
def load_actions_attributes(execution_plan_id, attributes)
  adapter.load_actions_attributes(execution_plan_id, attributes).reject(&:empty?)
end
load_delayed_plan(execution_plan_id) click to toggle source
# File lib/dynflow/persistence.rb, line 104
def load_delayed_plan(execution_plan_id)
  hash = adapter.load_delayed_plan(execution_plan_id)
  return nil unless hash
  DelayedPlan.new_from_hash(@world, hash)
end
load_execution_plan(id) click to toggle source
# File lib/dynflow/persistence.rb, line 68
def load_execution_plan(id)
  execution_plan_hash = adapter.load_execution_plan(id)
  ExecutionPlan.new_from_hash(execution_plan_hash, @world)
end
load_step(execution_plan_id, step_id, world) click to toggle source
# File lib/dynflow/persistence.rb, line 110
def load_step(execution_plan_id, step_id, world)
  step_hash = adapter.load_step(execution_plan_id, step_id)
  ExecutionPlan::Steps::Abstract.from_hash(step_hash, execution_plan_id, world)
end
load_steps(execution_plan_id, world) click to toggle source
# File lib/dynflow/persistence.rb, line 115
def load_steps(execution_plan_id, world)
  adapter.load_steps(execution_plan_id).map do |step_hash|
    ExecutionPlan::Steps::Abstract.from_hash(step_hash, execution_plan_id, world)
  end
end
prune_envelopes(receiver_ids) click to toggle source
# File lib/dynflow/persistence.rb, line 138
def prune_envelopes(receiver_ids)
  adapter.prune_envelopes(receiver_ids)
end
prune_undeliverable_envelopes() click to toggle source
# File lib/dynflow/persistence.rb, line 142
def prune_undeliverable_envelopes
  adapter.prune_undeliverable_envelopes
end
pull_envelopes(world_id) click to toggle source
# File lib/dynflow/persistence.rb, line 130
def pull_envelopes(world_id)
  adapter.pull_envelopes(world_id).map do |data|
    envelope = Dynflow.serializer.load(data)
    Type! envelope, Dispatcher::Envelope
    envelope
  end
end
push_envelope(envelope) click to toggle source
# File lib/dynflow/persistence.rb, line 125
def push_envelope(envelope)
  Type! envelope, Dispatcher::Envelope
  adapter.push_envelope(Dynflow.serializer.dump(envelope))
end
save_action(execution_plan_id, action) click to toggle source
# File lib/dynflow/persistence.rb, line 45
def save_action(execution_plan_id, action)
  adapter.save_action(execution_plan_id, action.id, action.to_hash)
end
save_delayed_plan(delayed_plan) click to toggle source
# File lib/dynflow/persistence.rb, line 93
def save_delayed_plan(delayed_plan)
  adapter.save_delayed_plan(delayed_plan.execution_plan_uuid, delayed_plan.to_hash)
end
save_execution_plan(execution_plan) click to toggle source
# File lib/dynflow/persistence.rb, line 73
def save_execution_plan(execution_plan)
  adapter.save_execution_plan(execution_plan.id, execution_plan.to_hash)
end
save_step(step, conditions = {}) click to toggle source
# File lib/dynflow/persistence.rb, line 121
def save_step(step, conditions = {})
  adapter.save_step(step.execution_plan_id, step.id, step.to_hash, conditions)
end
set_delayed_plan_frozen(execution_plan_id, frozen = true, new_start_at = nil) click to toggle source
# File lib/dynflow/persistence.rb, line 97
def set_delayed_plan_frozen(execution_plan_id, frozen = true, new_start_at = nil)
  plan = load_delayed_plan(execution_plan_id)
  plan.frozen = frozen
  plan.start_at = new_start_at if new_start_at
  save_delayed_plan(plan)
end