Sha256: 35052ff9c570dd516bbdee14f8ab540695b370aa1513dbd79ffd05cfaf4537be
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
require 'google-cloud-tasks' module RailsCloudTasks class Adapter delegate :project_id, :location_id, :host, :tasks_path, :auth, to: 'RailsCloudTasks.config' def enqueue(job, timestamp = nil) path = client.queue_path(project: project_id, location: location_id, queue: job.queue_name) task = build_task(job, timestamp) begin client.create_task(parent: path, task: task) rescue Google::Cloud::FailedPreconditionError => e raise e if e.details != 'Queue does not exist.' client.create_queue(build_queue(path)) retry end end def enqueue_at(job, timestamp) enqueue(job, timestamp.to_i) end def client @client ||= Google::Cloud::Tasks.cloud_tasks end private def url "#{host}#{tasks_path}" end def build_task(job, timestamp) { http_request: { http_method: :POST, url: url, body: { job: job.serialize }.to_json.force_encoding('ASCII-8BIT'), headers: { 'Content-Type': 'application/json' } }.merge(auth), schedule_time: timestamp && Google::Protobuf::Timestamp.new.tap do |ts| ts.seconds = timestamp end }.compact end def build_queue(path) { parent: path.split('/queues').first, queue: { name: path } } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rails-cloud-tasks-0.0.10 | lib/rails_cloud_tasks/adapter.rb |
rails-cloud-tasks-0.0.9 | lib/rails_cloud_tasks/adapter.rb |
rails-cloud-tasks-0.0.9.pre.rc | lib/rails_cloud_tasks/adapter.rb |