Class: ActiveJob::GoogleCloudPubsub::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/activejob-google_cloud_pubsub/adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(async: true, pubsub: Google::Cloud::Pubsub.new, logger: Logger.new($stdout)) ⇒ Adapter

Returns a new instance of Adapter.



12
13
14
15
16
# 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

Instance Method Details

#enqueue(job, attributes = {}) ⇒ Object



18
19
20
21
22
23
24
# 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) ⇒ Object



26
27
28
# File 'lib/activejob-google_cloud_pubsub/adapter.rb', line 26

def enqueue_at(job, timestamp)
  enqueue job, timestamp: timestamp
end