Class: Naf::ApplicationSchedule
- Includes:
- PgAdvisoryLocker
- Defined in:
- app/models/naf/application_schedule.rb
Constant Summary collapse
- SCHEDULES_LOCK_ID =
0
Class Method Summary collapse
- .exact_schedules ⇒ Object
- .pickables ⇒ Object
- .pickleables(pickler) ⇒ Object
- .relative_schedules ⇒ Object
-
.try_lock_schedules ⇒ Object
———————- *** Class Methods *** ++++++++++++++++++++++.
- .unlock_schedules ⇒ Object
Instance Method Summary collapse
- #enabled_application_id_unique ⇒ Object
- #run_interval_at_time_check ⇒ Object
-
#to_s ⇒ Object
————————- *** Instance Methods *** +++++++++++++++++++++++++.
- #visible_enabled_check ⇒ Object
Methods inherited from NafBase
Class Method Details
.exact_schedules ⇒ Object
97 98 99 |
# File 'app/models/naf/application_schedule.rb', line 97 def self.exact_schedules where('run_start_minute is not null') end |
.pickables ⇒ Object
105 106 107 108 |
# File 'app/models/naf/application_schedule.rb', line 105 def self.pickables # check the application is deleted self.where(:deleted => false) end |
.pickleables(pickler) ⇒ Object
163 164 165 166 |
# File 'app/models/naf/application_schedule.rb', line 163 def self.pickleables(pickler) self.joins(:application). where("#{::Naf.schema_name}.applications.deleted IS FALSE") end |
.relative_schedules ⇒ Object
101 102 103 |
# File 'app/models/naf/application_schedule.rb', line 101 def self.relative_schedules where('run_interval >= 0') end |
.try_lock_schedules ⇒ Object
*** Class Methods *** ++++++++++++++++++++++
89 90 91 |
# File 'app/models/naf/application_schedule.rb', line 89 def self.try_lock_schedules try_lock_record(SCHEDULES_LOCK_ID) end |
.unlock_schedules ⇒ Object
93 94 95 |
# File 'app/models/naf/application_schedule.rb', line 93 def self.unlock_schedules unlock_record(SCHEDULES_LOCK_ID) end |
Instance Method Details
#enabled_application_id_unique ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'app/models/naf/application_schedule.rb', line 143 def enabled_application_id_unique return unless enabled if id conditions = ["id <> ? AND application_id = ? AND enabled = ?", id, application_id, true] else conditions = ["application_id = ? AND enabled = ?", application_id, true] end num_collisions = self.class.count(conditions: conditions) errors.add(:application_id, "is enabled and has already been taken") if num_collisions > 0 end |
#run_interval_at_time_check ⇒ Object
156 157 158 159 160 161 |
# File 'app/models/naf/application_schedule.rb', line 156 def run_interval_at_time_check unless (run_start_minute.blank? || run_interval.blank?) errors.add(:run_interval, "or Run start minute must be nil") errors.add(:run_start_minute, "or Run interval must be nil") end end |
#to_s ⇒ Object
*** Instance Methods *** +++++++++++++++++++++++++
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/naf/application_schedule.rb', line 114 def to_s components = [] if enabled components << "ENABLED" else if visible components << "DISABLED" else components << "HIDDEN|DISABLED" end end components << "id: #{id}" components << "\"#{application.title}\"" if run_start_minute components << "start at: #{"%02d" % (run_start_minute/60)}:#{"%02d" % (run_start_minute%60)}" else components << "start every: #{run_interval} minutes" end return "::Naf::ApplicationSchedule<#{components.join(', ')}>" end |
#visible_enabled_check ⇒ Object
136 137 138 139 140 141 |
# File 'app/models/naf/application_schedule.rb', line 136 def visible_enabled_check unless visible or !enabled errors.add(:visible, "must be true, or set enabled to false") errors.add(:enabled, "must be false, if visible is set to false") end end |