Class: Babushka::Task

Inherits:
Object show all
Includes:
LogHelpers, PathHelpers, ShellHelpers, Singleton
Defined in:
lib/babushka/task.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from ShellHelpers

#cmd_dir, #failable_shell, #log_shell, #login_shell, #raw_shell, #shell, #shell!, #shell?, #sudo, #which

Methods included from LogHelpers

#debug, #log, #log_block, #log_error, #log_ok, #log_verbose, #log_warn

Methods included from PathHelpers

#cd, #in_build_dir, #in_dir, #in_download_dir

Constructor Details

- (Task) initialize

A new instance of Task



11
12
13
14
15
# File 'lib/babushka/task.rb', line 11

def initialize
  @vars = Vars.new
  @opts = Base.cmdline.opts.dup
  @running = false
end

Instance Attribute Details

- (Object) opts (readonly)

Returns the value of attribute opts



8
9
10
# File 'lib/babushka/task.rb', line 8

def opts
  @opts
end

- (Object) persistent_log (readonly)

Returns the value of attribute persistent_log



8
9
10
# File 'lib/babushka/task.rb', line 8

def persistent_log
  @persistent_log
end

- (Object) reportable

Returns the value of attribute reportable



9
10
11
# File 'lib/babushka/task.rb', line 9

def reportable
  @reportable
end

- (Object) vars (readonly)

Returns the value of attribute vars



8
9
10
# File 'lib/babushka/task.rb', line 8

def vars
  @vars
end

Instance Method Details

- (Object) callstack



60
61
62
# File 'lib/babushka/task.rb', line 60

def callstack
  @callstack ||= []
end

- (Object) log_path_for(dep)



64
65
66
# File 'lib/babushka/task.rb', line 64

def log_path_for dep
  log_prefix / dep.contextual_name
end

- (Object) opt(name)



52
53
54
# File 'lib/babushka/task.rb', line 52

def opt name
  opts[name]
end

- (Object) process(dep_names, with_vars = {})



17
18
19
20
21
22
23
24
# File 'lib/babushka/task.rb', line 17

def process dep_names, with_vars = {}
  raise "A task is already running." if running?
  @running = true
  Base.in_thread { RunReporter.post_reports }
  dep_names.all? {|dep_name| process_dep dep_name, with_vars }
ensure
  @running = false
end

- (Object) process_dep(dep_name, with_vars)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/babushka/task.rb', line 26

def process_dep dep_name, with_vars
  Dep.find_or_suggest dep_name do |dep|
    log_dep(dep) {
      load_run_info_for dep, with_vars
      dep.with(task_args_for(dep, with_vars)).process(:top_level => true).tap {|result|
        save_run_info_for dep, result
      }
    }.tap {|result|
      log "You can view #{opt(:debug) ? 'the' : 'a more detailed'} log at '#{log_path_for(dep)}'." unless result
      RunReporter.queue dep, result, reportable
      BugReporter.report dep if reportable
    }
  end
end

- (Boolean) running?

Returns:

  • (Boolean)


56
57
58
# File 'lib/babushka/task.rb', line 56

def running?
  @running
end

- (Object) task_info(dep, result)



41
42
43
44
45
46
47
48
49
50
# File 'lib/babushka/task.rb', line 41

def task_info dep, result
  {
    :version => VERSION,
    :run_at => Time.now,
    :system_info => Base.host.description,
    :dep_name => dep.name,
    :source_uri => dep.dep_source.uri,
    :result => result
  }
end

- (Object) var_path_for(dep)



68
69
70
# File 'lib/babushka/task.rb', line 68

def var_path_for dep
  VarsPrefix.p / dep.contextual_name
end