class ActiveJob::GoogleCloudPubsub::GoogleCloudPubsubAdapter

Public Class Methods

new(async: true, pubsub: Google::Cloud::Pubsub.new, logger: Logger.new($stdout)) click to toggle source
# File lib/activejob-google_cloud_pubsub/adapter.rb, line 12
def initialize(async: true, pubsub: Google::Cloud::Pubsub.new, logger: Logger.new($stdout))
  @executor = async ? :io : :immediate
  @pubsub   = pubsub
  @logger   = logger
end

Public Instance Methods

enqueue(job, attributes = {}) click to toggle source
# File lib/activejob-google_cloud_pubsub/adapter.rb, line 18
def enqueue(job, attributes = {})
  Concurrent::Promise.execute(executor: @executor) {
    @pubsub.topic_for(job.queue_name).publish JSON.dump(job.serialize), attributes
  }.rescue {|e|
    @logger&.error e
  }
end
enqueue_at(job, timestamp) click to toggle source
# File lib/activejob-google_cloud_pubsub/adapter.rb, line 26
def enqueue_at(job, timestamp)
  enqueue job, timestamp: timestamp
end