Class: Activejob::GoogleCloudTasks::Adapter
- Inherits:
-
Object
- Object
- Activejob::GoogleCloudTasks::Adapter
- Defined in:
- lib/activejob/google_cloud_tasks/adapter.rb
Instance Method Summary collapse
- #enqueue(job, attributes = {}) ⇒ Object
- #enqueue_at(job, scheduled_at) ⇒ Object
-
#initialize(project:, location:, cloud_tasks_client: Google::Cloud::Tasks.new(version: :v2beta3)) ⇒ Adapter
constructor
A new instance of Adapter.
Constructor Details
#initialize(project:, location:, cloud_tasks_client: Google::Cloud::Tasks.new(version: :v2beta3)) ⇒ Adapter
Returns a new instance of Adapter.
8 9 10 11 12 |
# File 'lib/activejob/google_cloud_tasks/adapter.rb', line 8 def initialize(project:, location:, cloud_tasks_client: Google::Cloud::Tasks.new(version: :v2beta3)) @project = project @location = location @cloud_tasks_client = cloud_tasks_client end |
Instance Method Details
#enqueue(job, attributes = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/activejob/google_cloud_tasks/adapter.rb', line 14 def enqueue(job, attributes = {}) formatted_parent = Google::Cloud::Tasks::V2beta3::CloudTasksClient.queue_path(@project, @location, job.queue_name) relative_uri = "#{Activejob::GoogleCloudTasks::Config.path}/perform?job=#{job.class.to_s}&#{job.arguments.to_param}" task = { app_engine_http_request: { http_method: :GET, relative_uri: relative_uri } } task[:schedule_time] = Google::Protobuf::Timestamp.new(seconds: attributes[:scheduled_at].to_i) if attributes.has_key?(:scheduled_at) @cloud_tasks_client.create_task(formatted_parent, task) end |
#enqueue_at(job, scheduled_at) ⇒ Object
28 29 30 |
# File 'lib/activejob/google_cloud_tasks/adapter.rb', line 28 def enqueue_at(job, scheduled_at) enqueue job, scheduled_at: scheduled_at end |