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.
114 115 116 117 118 119 120 121 |
# File 'lib/cloudtasker/cloud_task.rb', line 114 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 32 33 |
# 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 ||= begin 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 end |
.create(payload) ⇒ Cloudtasker::CloudTask
Create a new cloud task.
88 89 90 91 92 93 |
# File 'lib/cloudtasker/cloud_task.rb', line 88 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.
100 101 102 |
# File 'lib/cloudtasker/cloud_task.rb', line 100 def self.delete(id) backend.delete(id) end |
.find(id) ⇒ Cloudtasker::Cloudtask
Find a cloud task by id.
76 77 78 79 |
# File 'lib/cloudtasker/cloud_task.rb', line 76 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.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cloudtasker/cloud_task.rb', line 44 def self.gct_backend @gct_backend ||= begin 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 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.
65 66 67 |
# File 'lib/cloudtasker/cloud_task.rb', line 65 def self.setup_production_queue(**kwargs) gct_backend.setup_queue(**kwargs) end |
Instance Method Details
#==(other) ⇒ Boolean
Equality operator.
130 131 132 |
# File 'lib/cloudtasker/cloud_task.rb', line 130 def ==(other) other.is_a?(self.class) && other.id == id end |