Class: Cloudtasker::CloudTask
- Inherits:
-
Object
- Object
- Cloudtasker::CloudTask
- Defined in:
- lib/cloudtasker/cloud_task.rb
Overview
An interface class to manage tasks on the backend (Cloud Task or Redis)
Instance Attribute Summary collapse
-
#dispatch_deadline ⇒ Object
Returns the value of attribute dispatch_deadline.
-
#http_request ⇒ Object
Returns the value of attribute http_request.
-
#id ⇒ Object
Returns the value of attribute id.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#schedule_time ⇒ Object
Returns the value of attribute schedule_time.
Class Method Summary collapse
-
.backend ⇒ Backend::MemoryTask, ...
The backend to use for cloud tasks.
-
.create(payload) ⇒ Cloudtasker::CloudTask
Create a new cloud task.
-
.delete(id) ⇒ Object
Delete a cloud task by id.
-
.find(id) ⇒ Cloudtasker::Cloudtask
Find a cloud task by id.
-
.gct_backend ⇒ Cloudtasker::Backend::GoogleCloudTaskV1, Cloudtasker::Backend::GoogleCloudTaskV2
Return the GoogleCloudTaskV* backend to use based on the version of the currently installed google-cloud-tasks gem.
-
.setup_production_queue(**kwargs) ⇒ Google::Cloud::Tasks::V2::Queue, Google::Cloud::Tasks::V2beta3::Queue
Create the google cloud task queue based on provided parameters if it does not exist already.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality operator.
-
#initialize(id:, http_request:, schedule_time: nil, retries: 0, queue: nil, dispatch_deadline: nil) ⇒ CloudTask
constructor
Build a new instance of the class using a backend response payload.
Constructor Details
#initialize(id:, http_request:, schedule_time: nil, retries: 0, queue: nil, dispatch_deadline: nil) ⇒ CloudTask
Build a new instance of the class using a backend response payload.
110 111 112 113 114 115 116 117 |
# File 'lib/cloudtasker/cloud_task.rb', line 110 def initialize(id:, http_request:, schedule_time: nil, retries: 0, queue: nil, dispatch_deadline: nil) @id = id @http_request = http_request @schedule_time = schedule_time @retries = retries || 0 @queue = queue @dispatch_deadline = dispatch_deadline end |
Instance Attribute Details
#dispatch_deadline ⇒ Object
Returns the value of attribute dispatch_deadline.
6 7 8 |
# File 'lib/cloudtasker/cloud_task.rb', line 6 def dispatch_deadline @dispatch_deadline end |
#http_request ⇒ Object
Returns the value of attribute http_request.
6 7 8 |
# File 'lib/cloudtasker/cloud_task.rb', line 6 def http_request @http_request end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/cloudtasker/cloud_task.rb', line 6 def id @id end |
#queue ⇒ Object
Returns the value of attribute queue.
6 7 8 |
# File 'lib/cloudtasker/cloud_task.rb', line 6 def queue @queue end |
#retries ⇒ Object
Returns the value of attribute retries.
6 7 8 |
# File 'lib/cloudtasker/cloud_task.rb', line 6 def retries @retries end |
#schedule_time ⇒ Object
Returns the value of attribute schedule_time.
6 7 8 |
# File 'lib/cloudtasker/cloud_task.rb', line 6 def schedule_time @schedule_time end |
Class Method Details
.backend ⇒ Backend::MemoryTask, ...
The backend to use for cloud tasks.
] The cloud task backend.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cloudtasker/cloud_task.rb', line 18 def self.backend # Re-evaluate backend every time if testing mode enabled @backend = nil if defined?(Cloudtasker::Testing) @backend ||= if defined?(Cloudtasker::Testing) && Cloudtasker::Testing.in_memory? require 'cloudtasker/backend/memory_task' Backend::MemoryTask elsif Cloudtasker.config.mode.to_sym == :development require 'cloudtasker/backend/redis_task' Backend::RedisTask else gct_backend end end |
.create(payload) ⇒ Cloudtasker::CloudTask
Create a new cloud task.
84 85 86 87 88 89 |
# File 'lib/cloudtasker/cloud_task.rb', line 84 def self.create(payload) raise MaxTaskSizeExceededError if payload.to_json.bytesize > Config::MAX_TASK_SIZE resp = backend.create(payload)&.to_h resp ? new(**resp) : nil end |
.delete(id) ⇒ Object
Delete a cloud task by id.
96 97 98 |
# File 'lib/cloudtasker/cloud_task.rb', line 96 def self.delete(id) backend.delete(id) end |
.find(id) ⇒ Cloudtasker::Cloudtask
Find a cloud task by id.
72 73 74 75 |
# File 'lib/cloudtasker/cloud_task.rb', line 72 def self.find(id) payload = backend.find(id)&.to_h payload ? new(**payload) : nil end |
.gct_backend ⇒ Cloudtasker::Backend::GoogleCloudTaskV1, Cloudtasker::Backend::GoogleCloudTaskV2
Return the GoogleCloudTaskV* backend to use based on the version of the currently installed google-cloud-tasks gem
] The google cloud task backend.
42 43 44 45 46 47 48 49 50 |
# File 'lib/cloudtasker/cloud_task.rb', line 42 def self.gct_backend @gct_backend ||= if !defined?(Google::Cloud::Tasks::VERSION) || Google::Cloud::Tasks::VERSION < '2' require 'cloudtasker/backend/google_cloud_task_v1' Backend::GoogleCloudTaskV1 else require 'cloudtasker/backend/google_cloud_task_v2' Backend::GoogleCloudTaskV2 end end |
.setup_production_queue(**kwargs) ⇒ Google::Cloud::Tasks::V2::Queue, Google::Cloud::Tasks::V2beta3::Queue
Create the google cloud task queue based on provided parameters if it does not exist already.
61 62 63 |
# File 'lib/cloudtasker/cloud_task.rb', line 61 def self.setup_production_queue(**kwargs) gct_backend.setup_queue(**kwargs) end |
Instance Method Details
#==(other) ⇒ Boolean
Equality operator.
126 127 128 |
# File 'lib/cloudtasker/cloud_task.rb', line 126 def ==(other) other.is_a?(self.class) && other.id == id end |