Class: ActiveJob::QueueAdapters::GoogleCloudrunTasksAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/google_cloud_run/job_adapter.rb

Instance Method Summary collapse

Constructor Details

#initializeGoogleCloudrunTasksAdapter

Returns a new instance of GoogleCloudrunTasksAdapter.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/google_cloud_run/job_adapter.rb', line 6

def initialize
  @client = Google::Cloud::Tasks.cloud_tasks
  @project_id = GoogleCloudRun.project_id
  @service_account_email = GoogleCloudRun.
  @default_job_timeout_sec = Rails.application.config.google_cloudrun.job_timeout_sec
  @job_callback_url = Rails.application.config.google_cloudrun.job_callback_url
  @queue_default_region = Rails.application.config.google_cloudrun.job_queue_default_region

  if @job_callback_url.blank? || !@job_callback_url.end_with?(Rails.application.config.google_cloudrun.job_callback_path)
    raise "Set config.google_cloudrun.job_callback_url to 'https://your-domain.com#{Rails.application.config.google_cloudrun.job_callback_path}'"
  end

  if !@job_callback_url.start_with?("https://")
    raise "config.google_cloudrun.job_callback_url must start with https://"
  end
end

Instance Method Details

#enqueue(job) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/google_cloud_run/job_adapter.rb', line 23

def enqueue(job)
  create_cloudtask(job.class,
                   job.job_id,
                   job.queue_name,
                   local_timeout(job) || @default_job_timeout_sec,
                   nil,
                   job.serialize)
end

#enqueue_at(job, timestamp) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/google_cloud_run/job_adapter.rb', line 32

def enqueue_at(job, timestamp)
  create_cloudtask(job.class,
                   job.job_id,
                   job.queue_name,
                   local_timeout(job) || @default_job_timeout_sec,
                   timestamp,
                   job.serialize)
end