class Abid::Task

Attributes

extends[RW]
params[R]
play[R]
play_class_definition[RW]

Public Class Methods

new(task_name, app) click to toggle source
Calls superclass method
# File lib/abid/task.rb, line 10
def initialize(task_name, app)
  super(task_name, app)
  @siblings = {}
end

Public Instance Methods

bind(**params) click to toggle source
# File lib/abid/task.rb, line 30
def bind(**params)
  fail 'already bound' if bound?

  parsed_params = ParamsParser.parse(params, play_class.params_spec)
  return @siblings[parsed_params] if @siblings.include?(parsed_params)

  sorted_params = parsed_params.sort.to_h
  sorted_params.freeze

  @siblings[sorted_params] = dup.tap do |t|
    t.instance_eval do
      @prerequisites = []
      @params = sorted_params
      @play = play_class.new(t)
      call_play_hooks(:setup)
      bind_play_hooks(:before, :before_execute)
      bind_play_hooks(:after, :after_invoke)
    end
  end
end
bind_play_hooks(tag, to = nil) click to toggle source
# File lib/abid/task.rb, line 121
def bind_play_hooks(tag, to = nil)
  to ||= tag
  hooks[to] = [proc { |*args| call_play_hooks(tag, *args) }]
end
bound?() click to toggle source
# File lib/abid/task.rb, line 26
def bound?
  !@play.nil?
end
call_play_hooks(tag, *args) click to toggle source
# File lib/abid/task.rb, line 126
def call_play_hooks(tag, *args)
  return unless bound?
  play_class.hooks[tag].each { |blk| play.instance_exec(*args, &blk) }
end
concerned?() click to toggle source
# File lib/abid/task.rb, line 107
def concerned?
  state.reload

  if !application.options.retry_failed_job && !application.options.repair && state.failed? && !top_level?
    fail "#{name} -- task has been failed"
  end

  application.options.repair || !state.successed?
end
execute(_args = nil) click to toggle source

Execute the play associated with this task.

# File lib/abid/task.rb, line 93
def execute(_args = nil)
  fail 'no play is bound yet' unless bound?

  if application.options.dryrun
    application.trace "** Execute (dry run) #{name_with_params}"
    return
  end
  if application.options.trace
    application.trace "** Execute #{name_with_params}"
  end

  play.run
end
needed?() click to toggle source
# File lib/abid/task.rb, line 117
def needed?
  !state.successed? || prerequisite_tasks.any? { |t| t.session.successed? }
end
params_description() click to toggle source
# File lib/abid/task.rb, line 77
def params_description
  sig_params = play_class.params_spec.select do |_, spec|
    spec[:significant]
  end
  return if sig_params.empty?

  if bound? # unbound
    p = sig_params.map { |name, _| "#{name}=#{params[name]}" }
  else
    p = sig_params.map { |name, spec| "#{name}:#{spec[:type]}" }
  end

  p.join(' ')
end
play_class() click to toggle source
# File lib/abid/task.rb, line 15
def play_class
  return @play_class if @play_class

  task = self
  klass = application.lookup_play_class(extends, scope)
  @play_class = Class.new(klass) do |c|
    c.task = task
    c.class_eval(&task.play_class_definition)
  end
end
prerequisite_tasks() click to toggle source
# File lib/abid/task.rb, line 51
def prerequisite_tasks
  fail 'no play is bound yet' unless bound?

  prerequisites.map do |pre, params|
    application[pre, @scope, **self.params.merge(params)]
  end
end