Class: ShellElf::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/shell_elf/batch.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Batch

Returns a new instance of Batch.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shell_elf/batch.rb', line 9

def initialize(params)
  options = params[:options] || {}
  @commands = 
    if params[:command]
      [params[:command]]
    elsif params[:commands]
      params[:commands]
    else
      []
    end
  @success_postback = options.delete(:success)
  @failure_postback = options.delete(:failure)
end

Class Method Details

.execute(params) ⇒ Object



4
5
6
# File 'lib/shell_elf/batch.rb', line 4

def execute(params)
  new(params).execute
end

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shell_elf/batch.rb', line 23

def execute
  return self if @commands.empty?
  if @commands.all? { |command| Job.execute(command).success? }
    if @success_postback
      ShellElf.logger.debug("Posting back to #{@success_postback}")
      Net::HTTP.post_form(URI.parse(@success_postback), {})
    else
      ShellElf.logger.debug("No success postback given")
    end
  elsif @failure_postback
    ShellElf.logger.debug("Posting back to #{@failure_postback}")
    Net::HTTP.post_form(URI.parse(@failure_postback), {})
  else
    ShellElf.logger.debug("No failure postback given")
  end
  self
end