Module: Magellan::Gcs::Proxy::ProgressNotification

Includes:
Log
Included in:
Context
Defined in:
lib/magellan/gcs/proxy/progress_notification.rb

Defined Under Namespace

Classes: CompositeNotifier

Constant Summary

Constants included from Log

Log::CLOUD_LOGGING_RESOURCE_KEYS

Instance Method Summary collapse

Methods included from Log

build_cloud_logging_logger, build_logger, build_loggers, logger, loggers, verbose

Instance Method Details

#build_notifierObject

Build the Notifier object like these…

CompositeNotifier

@notifiers:
  PubsubProgressNotifier
  ProgressNotifierAdapter
    @logger:
      CompositeLogger
        @loggers:
          Logger
          Google::Cloud::Logging::Logger


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/magellan/gcs/proxy/progress_notification.rb', line 42

def build_notifier
  notifiers = []
  if c = Proxy.config[:progress_notification]
    notifiers << PubsubProgressNotifier.new(c['topic'])
  end
  notifiers << ProgressNotifierAdapter.new(logger)
  case notifiers.length
  when 1 then notifiers.first
  else CompositeNotifier.new(notifiers)
  end
end

#notifierObject



27
28
29
# File 'lib/magellan/gcs/proxy/progress_notification.rb', line 27

def notifier
  @notifier ||= build_notifier
end

#notify(progress, total, data, severity: :info) ⇒ Object



23
24
25
# File 'lib/magellan/gcs/proxy/progress_notification.rb', line 23

def notify(progress, total, data, severity: :info)
  notifier.notify(severity, message, data, progress: progress, total: total)
end

#process_with_notification(numbers, total, base_message, main = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/magellan/gcs/proxy/progress_notification.rb', line 9

def process_with_notification(numbers, total, base_message, main = nil)
  start_no, complete_no, error_no = *numbers
  notify(start_no, total, "#{base_message} starting")
  begin
    main ? main.call(self) : yield(self)
  rescue => e
    notify(error_no, total, "#{base_message} error: [#{e.class}] #{e.message}", severity: :error)
    raise e unless main
  else
    notify(complete_no, total, "#{base_message} completed")
    yield(self) if main
  end
end