Class: Rearview::Job
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Rearview::Job
- Includes:
- ConstantsModuleMaker, Ext::StateMachine
- Defined in:
- app/models/rearview/job.rb
Instance Attribute Summary collapse
-
#deep_validation ⇒ Object
writeonly
Sets the attribute deep_validation.
Instance Method Summary collapse
- #create_associated_event(transition) ⇒ Object
- #deep_validation? ⇒ Boolean
-
#delay ⇒ Object
The number of seconds to delay before the next time this job should run.
- #reset ⇒ Object
- #schedule ⇒ Object
-
#sync_monitor_service ⇒ Object
This doesn’t fit nicely as a callback – the monitor itself needs to update the job which triggers a fun cycle of events =).
- #unschedule ⇒ Object
- #update_associated_event(transition) ⇒ Object
- #valid_alert_keys ⇒ Object
Methods included from Ext::StateMachine
Methods included from ConstantsModuleMaker
Instance Attribute Details
#deep_validation=(value) ⇒ Object (writeonly)
Sets the attribute deep_validation
13 14 15 |
# File 'app/models/rearview/job.rb', line 13 def deep_validation=(value) @deep_validation = value end |
Instance Method Details
#create_associated_event(transition) ⇒ Object
141 142 143 144 145 146 147 |
# File 'app/models/rearview/job.rb', line 141 def create_associated_event(transition) report_transition(transition) job_error_attrs = {} job_error_attrs.merge!(event_data[:job_error]) if event_data.try(:[],:job_error) job_error = job_errors.create(job_error_attrs) job_error.fire_event(translate_associated_event(transition),event_data) end |
#deep_validation? ⇒ Boolean
157 158 159 |
# File 'app/models/rearview/job.rb', line 157 def deep_validation? @deep_validation end |
#delay ⇒ Object
The number of seconds to delay before the next time this job should run
101 102 103 104 105 106 107 |
# File 'app/models/rearview/job.rb', line 101 def delay if cron_expr == "0 * * * * ?" 60.0 else Rearview::CronHelper.next_valid_time_after(cron_expr) end end |
#reset ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'app/models/rearview/job.rb', line 90 def reset self.unschedule if active self.job_data.destroy unless(self.job_data.nil?) self.job_errors.clear self.status = nil self.save! self.reload self.schedule if active end |
#schedule ⇒ Object
82 83 84 |
# File 'app/models/rearview/job.rb', line 82 def schedule Rearview.monitor_service.schedule(self) end |
#sync_monitor_service ⇒ Object
This doesn’t fit nicely as a callback – the monitor itself needs to update the job which triggers a fun cycle of events =)
111 112 113 114 115 116 117 |
# File 'app/models/rearview/job.rb', line 111 def sync_monitor_service if active schedule else unschedule end end |
#unschedule ⇒ Object
86 87 88 |
# File 'app/models/rearview/job.rb', line 86 def unschedule Rearview.monitor_service.unschedule(self) end |
#update_associated_event(transition) ⇒ Object
149 150 151 152 153 154 155 |
# File 'app/models/rearview/job.rb', line 149 def update_associated_event(transition) report_transition(transition) job_error = Rearview::JobError.latest_entry(self) if job_error.present? job_error.fire_event(translate_associated_event(transition),event_data) end end |
#valid_alert_keys ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/rearview/job.rb', line 119 def valid_alert_keys if alert_keys.present? schemes = Rearview::Alerts.registry.keys alert_keys.each do |key| begin uri = URI(key) scheme = uri.scheme unless scheme.present? && schemes.include?(scheme) errors.add(:alert_keys,"#{key} is not a supported alert type") else scheme_class = Rearview::Alerts.registry[scheme] unless scheme_class.key?(key) errors.add(:alert_keys,"#{key} is invalid for supported alert type") end end rescue URI::InvalidURIError, URI::InvalidComponentError errors.add(:alert_keys,"#{key} is an invalid URI") end end end end |