Class: BrpmScriptExecutor

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

Class Method Summary collapse

Class Method Details

.execute_automation_script(modul, name, params) ⇒ Object Also known as: execute_automation_script_from_gem



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/brpm_script_executor.rb', line 5

def execute_automation_script(modul, name, params)
  begin
    BrpmAuto.setup(params)

    BrpmAuto.log ""
    BrpmAuto.log ">>>>>>>>>>>>>> START automation #{name}"
    start_time = Time.now

    BrpmAuto.log "Loading module #{modul}#{params["module_version"] ? " #{params["module_version"]}" : ""} and its dependencies..."
    module_path = BrpmAuto.require_module(modul, params["module_version"])
    BrpmAuto.log "Finished loading the module."

    automation_script_path = "#{module_path}/automations/#{name}.rb"

    BrpmAuto.log "Loading the automation script #{automation_script_path}..."
    load automation_script_path

  rescue Exception => e
    BrpmAuto.log_error "#{e}"
    BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")

    raise e
  ensure
    stop_time = Time.now
    duration = 0
    duration = stop_time - start_time unless start_time.nil?

    BrpmAuto.log ">>>>>>>>>>>>>> STOP automation #{name} - total duration: #{Time.at(duration).utc.strftime("%H:%M:%S")}"
    BrpmAuto.log ""

    #load "#{File.dirname(__FILE__)}/write_to.rb" if BrpmAuto.params.run_from_brpm
  end
end

.execute_resource_automation_script(modul, name, params, parent_id, offset, max_records) ⇒ Object Also known as: execute_resource_automation_script_from_gem



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/brpm_script_executor.rb', line 41

def execute_resource_automation_script(modul, name, params, parent_id, offset, max_records)
  begin
    BrpmAuto.setup(params)

    BrpmAuto.log ""
    BrpmAuto.log ">>>>>>>>>>>>>> START resource automation #{name}"
    start_time = Time.now

    BrpmAuto.log "Loading module #{modul} and its dependencies..."
    module_path = BrpmAuto.require_module(modul) #TODO: from where should we get the module version of the script?
    BrpmAuto.log "Finished loading the module."

    automation_script_path = "#{module_path}/resource_automations/#{name}.rb"

    BrpmAuto.log "Loading the resource automation script #{automation_script_path}..."
    load automation_script_path

    BrpmAuto.log "Calling execute_resource_automation_script(params, parent_id, offset, max_records)..."
    execute_script(params, parent_id, offset, max_records)

  rescue Exception => e
    BrpmAuto.log_error "#{e}"
    BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")

    raise e
  ensure
    stop_time = Time.now
    duration = stop_time - start_time

    BrpmAuto.log ">>>>>>>>>>>>>> STOP resource automation #{name} - total duration: #{Time.at(duration).utc.strftime("%H:%M:%S")}"
    BrpmAuto.log ""

    #load "#{File.dirname(__FILE__)}/write_to.rb" if BrpmAuto.params.run_from_brpm
  end
end