Class: Proby::ProbyTask
- Inherits:
-
ProbyHttpApi
- Object
- ProbyHttpApi
- Proby::ProbyTask
- Defined in:
- lib/proby/proby_task.rb
Overview
Represents a task in Proby
Instance Attribute Summary collapse
-
#api_id ⇒ Object
readonly
The API Task ID of the task.
-
#consecutive_alarmed_tasks ⇒ Object
readonly
The number of consecutive times this task has triggered an alarm.
-
#consecutive_alarmed_tasks_required_to_trigger_alarm ⇒ Object
The number of consecutive tasks that must fail before an alarm is sent.
-
#created_at ⇒ Object
readonly
The date and time this task was created.
-
#crontab ⇒ Object
The schedule for the task, specified in crontab format.
-
#finish_alarms_enabled ⇒ Object
Should finish alarms be sent when the task runs longer than expected?.
-
#machine ⇒ Object
The name of the machine that is responsible for running this task.
-
#maximum_run_time ⇒ Object
The maximum amount of time the task is allowed to run before Proby sends a finish alarm.
-
#name ⇒ Object
The name of the task.
-
#paused ⇒ Object
readonly
Is the task currently paused?.
-
#start_notification_grace_period ⇒ Object
The number of minutes to wait for a task to send its start notification after it should have started before sending an alarm.
-
#status ⇒ Object
readonly
The current status of the task, represented as a ProbyTaskStatus.
-
#time_zone ⇒ Object
The time zone of the machine executing the task.
-
#updated_at ⇒ Object
readonly
The date and time this task was updated.
Class Method Summary collapse
-
.create(attributes = {}) ⇒ ProbyTask
Create a new Proby task.
-
.find(param) ⇒ Object
Get a single, or all tasks from Proby.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete a Proby task.
-
#initialize(attributes = {}) ⇒ ProbyTask
constructor
Should not be called directly.
-
#pause ⇒ Object
Pause a Proby task.
-
#save ⇒ Object
Saves the task in Proby, updating all attributes to the values stored in the object.
-
#unpause ⇒ Object
Unpause a Proby task.
Constructor Details
#initialize(attributes = {}) ⇒ ProbyTask
Should not be called directly
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/proby/proby_task.rb', line 65 def initialize(attributes={}) @name = attributes['name'] @api_id = attributes['api_id'] @crontab = attributes['crontab'] @paused = attributes['paused'] @time_zone = attributes['time_zone'] @machine = attributes['machine'] @finish_alarms_enabled = attributes['finish_alarms_enabled'] @maximum_run_time = attributes['maximum_run_time'] @start_notification_grace_period = attributes['start_notification_grace_period'] @consecutive_alarmed_tasks = attributes['consecutive_alarmed_tasks'] @consecutive_alarmed_tasks_required_to_trigger_alarm = attributes['consecutive_alarmed_tasks_required_to_trigger_alarm'] @created_at = Chronic.parse attributes['created_at'] @updated_at = Chronic.parse attributes['updated_at'] @status = ProbyTaskStatus.new(attributes['status']) if attributes['status'] end |
Instance Attribute Details
#api_id ⇒ Object (readonly)
The API Task ID of the task
47 48 49 |
# File 'lib/proby/proby_task.rb', line 47 def api_id @api_id end |
#consecutive_alarmed_tasks ⇒ Object (readonly)
The number of consecutive times this task has triggered an alarm
53 54 55 |
# File 'lib/proby/proby_task.rb', line 53 def consecutive_alarmed_tasks @consecutive_alarmed_tasks end |
#consecutive_alarmed_tasks_required_to_trigger_alarm ⇒ Object
The number of consecutive tasks that must fail before an alarm is sent
44 45 46 |
# File 'lib/proby/proby_task.rb', line 44 def consecutive_alarmed_tasks_required_to_trigger_alarm @consecutive_alarmed_tasks_required_to_trigger_alarm end |
#created_at ⇒ Object (readonly)
The date and time this task was created
56 57 58 |
# File 'lib/proby/proby_task.rb', line 56 def created_at @created_at end |
#crontab ⇒ Object
The schedule for the task, specified in crontab format
23 24 25 |
# File 'lib/proby/proby_task.rb', line 23 def crontab @crontab end |
#finish_alarms_enabled ⇒ Object
Should finish alarms be sent when the task runs longer than expected?
32 33 34 |
# File 'lib/proby/proby_task.rb', line 32 def finish_alarms_enabled @finish_alarms_enabled end |
#machine ⇒ Object
The name of the machine that is responsible for running this task
29 30 31 |
# File 'lib/proby/proby_task.rb', line 29 def machine @machine end |
#maximum_run_time ⇒ Object
The maximum amount of time the task is allowed to run before Proby sends a finish alarm. If not specified, Proby will determine when an alarm should be sent based on past run times
37 38 39 |
# File 'lib/proby/proby_task.rb', line 37 def maximum_run_time @maximum_run_time end |
#name ⇒ Object
The name of the task
20 21 22 |
# File 'lib/proby/proby_task.rb', line 20 def name @name end |
#paused ⇒ Object (readonly)
Is the task currently paused?
50 51 52 |
# File 'lib/proby/proby_task.rb', line 50 def paused @paused end |
#start_notification_grace_period ⇒ Object
The number of minutes to wait for a task to send its start notification after it should have started before sending an alarm
41 42 43 |
# File 'lib/proby/proby_task.rb', line 41 def start_notification_grace_period @start_notification_grace_period end |
#status ⇒ Object (readonly)
The current status of the task, represented as a ProbyTaskStatus
62 63 64 |
# File 'lib/proby/proby_task.rb', line 62 def status @status end |
#time_zone ⇒ Object
The time zone of the machine executing the task
26 27 28 |
# File 'lib/proby/proby_task.rb', line 26 def time_zone @time_zone end |
#updated_at ⇒ Object (readonly)
The date and time this task was updated
59 60 61 |
# File 'lib/proby/proby_task.rb', line 59 def updated_at @updated_at end |
Class Method Details
.create(attributes = {}) ⇒ ProbyTask
Create a new Proby task.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/proby/proby_task.rb', line 119 def self.create(attributes={}) ensure_api_key_set raise InvalidParameterException.new("attributes are required") if attributes.nil? || attributes.empty? raise InvalidParameterException.new("name is required") unless !blank?(attributes[:name]) || !blank?(attributes['name']) raise InvalidParameterException.new("crontab is required") unless !blank?(attributes[:crontab]) || !blank?(attributes['crontab']) Proby.logger.info "Creating task with attributes: #{attributes.inspect}" response = post("/api/v1/tasks.json", :format => :json, :body => MultiJson.encode(:task => attributes), :headers => default_headers) if response.code == 201 new(response.parsed_response['task']) else handle_api_failure(response) end end |
.find(param) ⇒ Object
Get a single, or all tasks from Proby.
92 93 94 95 |
# File 'lib/proby/proby_task.rb', line 92 def self.find(param) ensure_api_key_set param == :all ? list : fetch(param) end |
Instance Method Details
#delete ⇒ Object
Delete a Proby task. The object will be frozen after the delete.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/proby/proby_task.rb', line 180 def delete self.class.ensure_api_key_set Proby.logger.info "Deleting task #{@api_id}" response = self.class.delete("/api/v1/tasks/#{@api_id}.json", :format => :json, :headers => self.class.default_headers) if response.code == 200 self.freeze true else self.class.handle_api_failure(response) end end |
#pause ⇒ Object
Pause a Proby task.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/proby/proby_task.rb', line 201 def pause self.class.ensure_api_key_set Proby.logger.info "Pausing task #{@api_id}" response = self.class.post("/api/v1/tasks/#{@api_id}/pause.json", :format => :json, :headers => self.class.default_headers) if response.code == 200 @paused = true true else self.class.handle_api_failure(response) end end |
#save ⇒ Object
Saves the task in Proby, updating all attributes to the values stored in the object. Only the attributes specified in the ProbyTask.create documentation can be updated.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/proby/proby_task.rb', line 146 def save self.class.ensure_api_key_set raise InvalidParameterException.new("name is required") if self.class.blank?(@name) raise InvalidParameterException.new("crontab is required") if self.class.blank?(@crontab) attributes = { :name => @name, :crontab => @crontab, :time_zone => @time_zone, :machine => @machine, :finish_alarms_enabled => @finish_alarms_enabled, :maximum_run_time => @maximum_run_time, :start_notification_grace_period => @start_notification_grace_period, :consecutive_alarmed_tasks_required_to_trigger_alarm => @consecutive_alarmed_tasks_required_to_trigger_alarm } Proby.logger.info "Updating task #{@api_id} with attributes: #{attributes.inspect}" response = self.class.put("/api/v1/tasks/#{@api_id}.json", :format => :json, :body => MultiJson.encode(:task => attributes), :headers => self.class.default_headers) if response.code == 200 true else self.class.handle_api_failure(response) end end |
#unpause ⇒ Object
Unpause a Proby task.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/proby/proby_task.rb', line 222 def unpause self.class.ensure_api_key_set Proby.logger.info "Unpausing task #{@api_id}" response = self.class.post("/api/v1/tasks/#{@api_id}/unpause.json", :format => :json, :headers => self.class.default_headers) if response.code == 200 @paused = false true else self.class.handle_api_failure(response) end end |