Class: Magellan::Gcs::Proxy::Cli
- Inherits:
-
Object
- Object
- Magellan::Gcs::Proxy::Cli
- Includes:
- Log
- Defined in:
- lib/magellan/gcs/proxy/cli.rb
Constant Summary collapse
- TOTAL =
14
Constants included from Log
Log::CLOUD_LOGGING_RESOURCE_KEYS
Instance Attribute Summary collapse
-
#cmd_template ⇒ Object
readonly
Returns the value of attribute cmd_template.
Instance Method Summary collapse
- #build_command(context) ⇒ Object
-
#initialize(*args) ⇒ Cli
constructor
A new instance of Cli.
- #process(msg) ⇒ Object
- #process_with_error_handling(msg) ⇒ Object
- #run ⇒ Object
Methods included from Log
build_cloud_logging_logger, build_logger, build_loggers, logger, loggers, verbose
Constructor Details
#initialize(*args) ⇒ Cli
Returns a new instance of Cli.
16 17 18 |
# File 'lib/magellan/gcs/proxy/cli.rb', line 16 def initialize(*args) @cmd_template = args.join(' ') end |
Instance Attribute Details
#cmd_template ⇒ Object (readonly)
Returns the value of attribute cmd_template.
15 16 17 |
# File 'lib/magellan/gcs/proxy/cli.rb', line 15 def cmd_template @cmd_template end |
Instance Method Details
#build_command(context) ⇒ Object
59 60 61 62 |
# File 'lib/magellan/gcs/proxy/cli.rb', line 59 def build_command(context) msg_wrapper = MessageWrapper.new(context) ExpandVariable.(cmd_template, msg_wrapper) end |
#process(msg) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/magellan/gcs/proxy/cli.rb', line 39 def process(msg) context = Context.new(msg) context.notify(1, TOTAL, "Processing message: #{msg.inspect}") context.setup do context.process_with_notification([2, 3, 4], TOTAL, 'Download', &:download) cmd = build_command(context) exec = ->(*) { LoggerPipe.run(logger, cmd, returns: :none, logging: :both, dry_run: Proxy.config[:dryrun]) } context.process_with_notification([5, 6, 7], TOTAL, 'Command', exec) do context.process_with_notification([8, 9, 10], TOTAL, 'Upload', &:upload) context.process_with_notification([11, 12, 13], TOTAL, 'Acknowledge') do msg.acknowledge! end end end context.notify(14, TOTAL, 'Cleanup') end |
#process_with_error_handling(msg) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/magellan/gcs/proxy/cli.rb', line 31 def process_with_error_handling(msg) process(msg) rescue => e logger.error("[#{e.class.name}] #{e.}") verbose("Backtrace\n " << e.backtrace.join("\n ")) end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/magellan/gcs/proxy/cli.rb', line 20 def run logger.info("#{$PROGRAM_NAME}-#{VERSION} is running") logger.info('Start listening') GCP.subscription.listen do |msg| process_with_error_handling(msg) end rescue => e logger.error("[#{e.class.name}] #{e.}") raise e end |