Class: Magellan::Gcs::Proxy::PubsubProgressNotifier

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/magellan/gcs/proxy/pubsub_progress_notifier.rb

Constant Summary

Constants included from Log

Log::CLOUD_LOGGING_RESOURCE_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

build_cloud_logging_logger, build_logger, build_loggers, logger, loggers, verbose

Constructor Details

#initialize(topic_name) ⇒ PubsubProgressNotifier

Returns a new instance of PubsubProgressNotifier.



14
15
16
# File 'lib/magellan/gcs/proxy/pubsub_progress_notifier.rb', line 14

def initialize(topic_name)
  @topic_name = topic_name
end

Instance Attribute Details

#topic_nameObject (readonly)

Returns the value of attribute topic_name.



13
14
15
# File 'lib/magellan/gcs/proxy/pubsub_progress_notifier.rb', line 13

def topic_name
  @topic_name
end

Instance Method Details

#notify(severity, job_message, data, attrs) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/magellan/gcs/proxy/pubsub_progress_notifier.rb', line 22

def notify(severity, job_message, data, attrs)
  attrs = { level: severity, job_message_id: job_message.message_id }.merge(attrs)
  # attrs must be an [Hash<String,String>]
  attrs = attrs.each_with_object({}) { |(k, v), d| d[k.to_s] = v.to_s }
  logger.debug("Publishing progress: #{attrs.inspect}")
  msg = Google::Apis::PubsubV1::Message.new(data: data, attributes: attrs)
  req = Google::Apis::PubsubV1::PublishRequest.new(messages: [msg])
  GCP.pubsub.publish_topic(topic_name, req)
end

#topicObject



18
19
20
# File 'lib/magellan/gcs/proxy/pubsub_progress_notifier.rb', line 18

def topic
  @topic ||= GCP.pubsub.topic(topic_name)
end