class Bricolage::Application
Public Class Methods
install_signal_handlers()
click to toggle source
# File lib/bricolage/application.rb, line 22 def Application.install_signal_handlers Signal.trap('PIPE', 'IGNORE') PostgresConnection.install_signal_handlers end
main()
click to toggle source
# File lib/bricolage/application.rb, line 27 def Application.main install_signal_handlers new.main end
new()
click to toggle source
# File lib/bricolage/application.rb, line 32 def initialize @hooks = Bricolage @start_time = Time.now end
Public Instance Methods
build_log_locator(job)
click to toggle source
# File lib/bricolage/application.rb, line 93 def build_log_locator(job) @log_locator_builder.build( job_ref: JobNet::JobRef.new(job.subsystem, job.id, '-'), jobnet_id: "#{job.subsystem}/#{job.id}", job_start_time: @start_time, jobnet_start_time: @start_time ) end
error_exit(msg)
click to toggle source
# File lib/bricolage/application.rb, line 161 def error_exit(msg) print_error msg exit 1 end
list_declarations(decls)
click to toggle source
# File lib/bricolage/application.rb, line 145 def list_declarations(decls) decls.each do |decl| if decl.have_default_value? puts "#{decl.name}\t= #{decl.default_value.inspect}" else puts decl.name end end end
list_variables(vars)
click to toggle source
# File lib/bricolage/application.rb, line 139 def list_variables(vars) vars.each_variable do |var| puts "#{var.name}=#{var.value.inspect}" end end
load_job(ctx, opts)
click to toggle source
# File lib/bricolage/application.rb, line 102 def load_job(ctx, opts) if opts.file_mode? Job.load_file(opts.job_file, ctx) else usage_exit "no job class given", opts.help if ARGV.empty? job_class_id = ARGV.shift Job.instantiate(nil, job_class_id, ctx) end rescue ParameterError => ex raise if $DEBUG usage_exit ex.message, opts.help end
main()
click to toggle source
# File lib/bricolage/application.rb, line 37 def main opts = GlobalOptions.new(self) @hooks.run_before_option_parsing_hooks(opts) opts.parse!(ARGV) @ctx = Context.for_application(opts.home, opts.job_file, environment: opts.environment, global_variables: opts.global_variables) opts.merge_saved_options(@ctx.load_system_options) if opts.dump_options? opts.option_pairs.each do |name, value| puts "#{name}=#{value.inspect}" end exit 0 end if opts.list_global_variables? list_variables @ctx.global_variables.resolve exit 0 end job = load_job(@ctx, opts) process_job_options(job, opts) job.compile if opts.list_declarations? list_declarations job.declarations exit 0 end if opts.list_variables? list_variables job.variables exit 0 end if opts.dry_run? puts job.script_source exit 0 end if opts.explain? job.explain exit 0 end @log_locator_builder = LogLocatorBuilder.for_options(@ctx, opts.log_path_format, opts.log_s3_ds, opts.log_s3_key_format) @hooks.run_before_all_jobs_hooks(BeforeAllJobsEvent.new(job.id, [job])) @hooks.run_before_job_hooks(BeforeJobEvent.new(job)) result = job.execute(log_locator: build_log_locator(job)) @hooks.run_after_job_hooks(AfterJobEvent.new(result)) @hooks.run_after_all_jobs_hooks(AfterAllJobsEvent.new(result.success?, [job])) exit result.status rescue OptionError => ex raise if $DEBUG usage_exit ex.message, opts.help rescue ApplicationError => ex raise if $DEBUG error_exit ex.message end
print_error(msg)
click to toggle source
# File lib/bricolage/application.rb, line 166 def print_error(msg) $stderr.puts "#{program_name}: error: #{msg}" end
process_job_options(job, opts)
click to toggle source
# File lib/bricolage/application.rb, line 115 def process_job_options(job, opts) parser = OptionParser.new parser.banner = "Usage: #{program_name} #{job.class_id} [job_class_options]" job.parsing_options {|job_opt_defs| job_opt_defs.define_options parser parser.on_tail('--help', 'Shows this message and quit.') { puts parser.help exit 0 } parser.on_tail('--version', 'Shows program version and quit.') { puts "#{APPLICATION_NAME} version #{VERSION}" exit 0 } parser.parse! } unless ARGV.empty? msg = opts.file_mode? ? "--job-file and job class argument is exclusive" : "bad argument: #{ARGV.first}" usage_exit msg, parser.help end rescue OptionError => ex raise if $DEBUG usage_exit ex.message, parser.help end
program_name()
click to toggle source
# File lib/bricolage/application.rb, line 170 def program_name File.basename($PROGRAM_NAME, '.*') end
usage_exit(msg, usage)
click to toggle source
# File lib/bricolage/application.rb, line 155 def usage_exit(msg, usage) print_error msg $stderr.puts usage exit 1 end