Class: Cron::JobTab
Constant Summary collapse
- FRAMEWORK_CLASSES =
%w[job trim_collection command server tab job_tab worker].freeze
Constants inherited from Tab
Tab::TIME_UNITS, Tab::WILDCARD
Class Method Summary collapse
- .ensure_cron_tabs ⇒ Object
-
.from_string(name, value) ⇒ Object
Pull form system configuration.
Instance Method Summary collapse
-
#cron_job_class ⇒ Object
Return the class associated with this job cron tab.
-
#run ⇒ Object
Run this job cron tab.
-
#to_string ⇒ Object
Convert back to a standard string value.
-
#update_from_string(value) ⇒ Object
Update our values based on the value.
-
#valid_environment? ⇒ Boolean
Is this enabled and a valid environment.
-
#valid_name ⇒ Object
Test the name is the list of jobs discovered.
Methods inherited from Tab
Methods included from SearchAble
included, #search_fields, #sort_fields, #update_search_and_sort_text, #update_text
Methods included from StandardModel
#clear_cache, included, #remove_blank_secure_fields, #secure_fields, #update, #update!
Methods included from App47Logger
#clean_params, #delete_parameter_keys, #log_controller_error, #log_debug, log_debug, log_error, #log_error, log_exception, #log_message, log_message, #log_warn, log_warn, #mask_parameter_keys, #update_flash_messages
Class Method Details
.ensure_cron_tabs ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/app/jobs/cron/job_tab.rb', line 30 def ensure_cron_tabs self.jobs = [] Cron.constants.each do |job| job_name = job.to_s.underscore next if FRAMEWORK_CLASSES.include?(job_name) || job_name.end_with?('_test') || job_name.start_with?('base_') jobs << job_name klass = "cron/#{job_name}".camelize.constantize tab = JobTab.find_or_initialize_by name: job_name next if tab.persisted? configure_cron_tab(tab, klass.cron_tab) end purge_cron_tabs end |
.from_string(name, value) ⇒ Object
Pull form system configuration
22 23 24 25 26 27 28 |
# File 'lib/app/jobs/cron/job_tab.rb', line 22 def from_string(name, value) tab = JobTab.find_or_initialize_by name: name return unless tab.valid? tab.update_from_string(value) tab end |
Instance Method Details
#cron_job_class ⇒ Object
Return the class associated with this job cron tab
108 109 110 |
# File 'lib/app/jobs/cron/job_tab.rb', line 108 def cron_job_class @cron_job_class ||= "cron/#{name}".camelize.constantize end |
#run ⇒ Object
Run this job cron tab
91 92 93 94 95 96 |
# File 'lib/app/jobs/cron/job_tab.rb', line 91 def run return unless valid_environment? cron_job_class.perform_later super end |
#to_string ⇒ Object
Convert back to a standard string value
115 116 117 |
# File 'lib/app/jobs/cron/job_tab.rb', line 115 def to_string [min, hour, mday, month, wday].join(' ') end |
#update_from_string(value) ⇒ Object
Update our values based on the value
79 80 81 82 83 84 85 86 |
# File 'lib/app/jobs/cron/job_tab.rb', line 79 def update_from_string(value) values = value.split(' ') self.min = values[0] self.hour = values[1] self.mday = values[2] self.month = values[3] self.wday = values[4] end |
#valid_environment? ⇒ Boolean
Is this enabled and a valid environment
101 102 103 |
# File 'lib/app/jobs/cron/job_tab.rb', line 101 def valid_environment? enabled? && cron_job_class.valid_environment? end |
#valid_name ⇒ Object
Test the name is the list of jobs discovered
122 123 124 |
# File 'lib/app/jobs/cron/job_tab.rb', line 122 def valid_name errors.add(:name, 'Invalid Tab') unless jobs.include?(name) end |