class ActiveJob::GoogleCloudTasks::HTTP::Adapter
Public Class Methods
new(project:, location:, url:, task_options: {}, client: nil)
click to toggle source
# File lib/active_job/google_cloud_tasks/http/adapter.rb, line 9 def initialize(project:, location:, url:, task_options: {}, client: nil) @project = project @location = location @url = url @task_options = task_options @client = client end
Public Instance Methods
enqueue(job, attributes = {})
click to toggle source
# File lib/active_job/google_cloud_tasks/http/adapter.rb, line 17 def enqueue(job, attributes = {}) path = client.queue_path(project: @project, location: @location, queue: job.queue_name) task = build_task(job, attributes) client.create_task parent: path, task: task end
enqueue_at(job, scheduled_at)
click to toggle source
# File lib/active_job/google_cloud_tasks/http/adapter.rb, line 24 def enqueue_at(job, scheduled_at) enqueue job, scheduled_at: scheduled_at end
Private Instance Methods
build_task(job, attributes)
click to toggle source
# File lib/active_job/google_cloud_tasks/http/adapter.rb, line 34 def build_task(job, attributes) task = { http_request: { http_method: :POST, url: @url, headers: {'Content-Type' => 'application/json'}, body: JSON.dump(job: job.serialize).force_encoding(Encoding::ASCII_8BIT), **@task_options } } task[:schedule_time] = Google::Protobuf::Timestamp.new(seconds: attributes[:scheduled_at].to_i) if attributes.has_key?(:scheduled_at) task end
client()
click to toggle source
# File lib/active_job/google_cloud_tasks/http/adapter.rb, line 30 def client @client ||= Google::Cloud::Tasks.cloud_tasks(version: :v2beta3) end