Class: Cron::SwitchboardSyncConfiguration
- Inherits:
-
Job
- Object
- ActiveJob::Base
- ApplicationJob
- Job
- Cron::SwitchboardSyncConfiguration
- Defined in:
- lib/app/jobs/cron/switchboard_sync_configuration.rb
Overview
Sync configuration with switchboard
Instance Attribute Summary
Attributes inherited from ApplicationJob
Class Method Summary collapse
-
.valid_environment? ⇒ Boolean
Only run in environments where switchboard is configured.
Instance Method Summary collapse
-
#execute ⇒ Object
Cycle through all configuration keys.
-
#switchboard_url ⇒ Object
Generate the switchboard URL.
-
#update_config(config, key, value) ⇒ Object
First see if it’s updateable against system config, then see if it’s in JobCronTab.
Methods inherited from Job
cron_tab_entry, #notify_job_failure, #send_support_email
Methods inherited from ApplicationJob
#duration, #parse_payload, #perform, valid_environments
Methods included from App47Logger
clean_params, #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
.valid_environment? ⇒ Boolean
Only run in environments where switchboard is configured
14 15 16 17 18 |
# File 'lib/app/jobs/cron/switchboard_sync_configuration.rb', line 14 def self.valid_environment? SystemConfiguration.switchboard_configured? rescue StandardError false end |
Instance Method Details
#execute ⇒ Object
Cycle through all configuration keys
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/app/jobs/cron/switchboard_sync_configuration.rb', line 23 def execute RestClient.get(switchboard_url, ACCESS_TOKEN: SystemConfiguration.switchboard_stack_api_token, content_type: 'application/json') do |response, _request, _result, &block| case response.code when 200 json = JSON.parse(response.body) config = SystemConfiguration.configuration json['results'].each { |key, value| update_config(config, key, value) } config.switchboard_last_sync_at = Time.now.utc config.save! else App47Logger.log_error "Unable to fetch switchboard config, #{response.inspect}" response.return!(&block) end end end |
#switchboard_url ⇒ Object
Generate the switchboard URL
61 62 63 64 65 66 |
# File 'lib/app/jobs/cron/switchboard_sync_configuration.rb', line 61 def switchboard_url [SystemConfiguration.switchboard_base_url, 'stacks', SystemConfiguration.switchboard_stack_id, 'items.json'].join('/') end |
#update_config(config, key, value) ⇒ Object
First see if it’s updateable against system config, then see if it’s in JobCronTab
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/app/jobs/cron/switchboard_sync_configuration.rb', line 44 def update_config(config, key, value) config.send("#{key}=", value) if config.respond_to?("#{key}=") return unless key.end_with?('_crontab') name = key.chomp('_crontab') tab = Cron::JobTab.from_string(name, value) if tab.present? && tab.valid? tab.save App47Logger.log_debug "Crontab #{name} updated with #{value}" else App47Logger.log_warn "Unable to update crontab #{name} updated with #{value}" end end |