Class: ActiveJob::GoogleCloudPubsub::Worker
- Inherits:
-
Object
- Object
- ActiveJob::GoogleCloudPubsub::Worker
- Defined in:
- lib/activejob_google_cloud_pubsub/worker.rb
Constant Summary collapse
- MAX_DEADLINE =
10.minutes
Instance Method Summary collapse
- #ensure_subscription ⇒ Object
-
#initialize(queue: 'default', pubsub: Google::Cloud::Pubsub.new(timeout: 60), logger: Logger.new($stdout)) ⇒ Worker
constructor
A new instance of Worker.
- #run ⇒ Object
Constructor Details
#initialize(queue: 'default', pubsub: Google::Cloud::Pubsub.new(timeout: 60), logger: Logger.new($stdout)) ⇒ Worker
Returns a new instance of Worker.
15 16 17 18 19 |
# File 'lib/activejob_google_cloud_pubsub/worker.rb', line 15 def initialize(queue: 'default', pubsub: Google::Cloud::Pubsub.new(timeout: 60), logger: Logger.new($stdout)) @queue_name = queue @pubsub = pubsub @logger = logger end |
Instance Method Details
#ensure_subscription ⇒ Object
36 37 38 39 40 |
# File 'lib/activejob_google_cloud_pubsub/worker.rb', line 36 def ensure_subscription @pubsub.subscription_for @queue_name nil end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/activejob_google_cloud_pubsub/worker.rb', line 21 def run subscriber = @pubsub.subscription_for(@queue_name).listen(streams: 1, threads: { callback: 1 }) do || @logger&.info "Message(#{.}) was received." process end subscriber.on_error do |error| @logger&.error(error) end subscriber.start sleep end |