Class: ActiveJob::GoogleCloudPubsub::Adapter
- Inherits:
-
Object
- Object
- ActiveJob::GoogleCloudPubsub::Adapter
- Defined in:
- lib/activejob_google_cloud_pubsub/adapter.rb
Instance Method Summary collapse
- #enqueue(job, attributes = {}) ⇒ Object
- #enqueue_at(job, timestamp) ⇒ Object
-
#initialize(async: true, pubsub: Google::Cloud::Pubsub.new(timeout: 60), logger: Logger.new($stdout)) ⇒ Adapter
constructor
A new instance of Adapter.
Constructor Details
#initialize(async: true, pubsub: Google::Cloud::Pubsub.new(timeout: 60), 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(timeout: 60), 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 25 |
# File 'lib/activejob_google_cloud_pubsub/adapter.rb', line 18 def enqueue(job, attributes = {}) promise = Concurrent::Promise.execute(executor: @executor) do @pubsub.topic_for(job.queue_name).publish JSON.dump(job.serialize), attributes end promise.rescue do |e| @logger&.error e end end |
#enqueue_at(job, timestamp) ⇒ Object
27 28 29 |
# File 'lib/activejob_google_cloud_pubsub/adapter.rb', line 27 def enqueue_at(job, ) enqueue job, timestamp: end |