split yaml file loading out of Setting

refs CNVS-13024

Setting wasn't properly being initialized as unsharded because
it was loading before Switchman. The reason we need Setting before
switchman is just for yaml loading, so split that into its own
class.

Change-Id: I5456e103cb216dba2d5af4e9c20a697b468c923b
Reviewed-on: https://gerrit.instructure.com/35043
Reviewed-by: Jacob Fugal <jacob@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2014-05-16 10:49:42 -06:00
parent 195c335aa4
commit 8178266194
39 changed files with 131 additions and 100 deletions

View File

@ -175,7 +175,7 @@ class AccountAuthorizationConfig < ActiveRecord::Base
end
def self.saml_settings_for_account(account, current_host=nil)
app_config = Setting.from_config('saml') || {}
app_config = ConfigFile.load('saml') || {}
domains = HostUrl.context_hosts(account, current_host)
settings = Onelogin::Saml::Settings.new

View File

@ -78,7 +78,7 @@ class Attachment < ActiveRecord::Base
def self.file_store_config
# Return existing value, even if nil, as long as it's defined
@file_store_config ||= Setting.from_config('file_store')
@file_store_config ||= ConfigFile.load('file_store')
@file_store_config ||= { 'storage' => 'local' }
@file_store_config['path_prefix'] ||= @file_store_config['path'] || 'tmp/files'
@file_store_config['path_prefix'] = nil if @file_store_config['path_prefix'] == 'tmp/files' && @file_store_config['storage'] == 's3'
@ -88,7 +88,7 @@ class Attachment < ActiveRecord::Base
def self.s3_config
# Return existing value, even if nil, as long as it's defined
return @s3_config if defined?(@s3_config)
@s3_config ||= Setting.from_config('amazon_s3')
@s3_config ||= ConfigFile.load('amazon_s3')
end
def self.s3_storage?

View File

@ -62,7 +62,7 @@ class CommunicationChannel < ActiveRecord::Base
RETIRE_THRESHOLD = 5
def self.sms_carriers
@sms_carriers ||= Canvas::ICU.collate_by((Setting.from_config('sms', false) ||
@sms_carriers ||= Canvas::ICU.collate_by((ConfigFile.load('sms', false) ||
{ 'AT&T' => 'txt.att.net',
'Alltel' => 'message.alltel.com',
'Boost' => 'myboostmobile.com',

View File

@ -482,7 +482,7 @@ class ContentMigration < ActiveRecord::Base
def download_exported_data
raise "No exported data to import" unless self.exported_attachment
config = Setting.from_config('external_migration') || {}
config = ConfigFile.load('external_migration') || {}
@exported_data_zip = self.exported_attachment.open(
:need_local_file => true,
:temp_folder => config[:data_folder])

View File

@ -83,7 +83,7 @@ class DeveloperKey < ActiveRecord::Base
# for now, only one AWS account for SNS is supported
def self.sns
if !defined?(@sns)
settings = Setting.from_config('sns')
settings = ConfigFile.load('sns')
@sns = nil
@sns = AWS::SNS.new(settings) if settings
end

View File

@ -17,10 +17,7 @@
#
class Setting < ActiveRecord::Base
# This is needed because Setting is called in Canvas.cache_store_config
# before switchman is loaded
cattr_accessor :shard_category unless self.respond_to?(:shard_category)
self.shard_category = :unsharded
self.shard_category = :unsharded if self.respond_to?(:shard_category=)
attr_accessible :name, :value
@ -73,38 +70,12 @@ class Setting < ActiveRecord::Base
s.destroy if s
end
# backcompat
def self.set_config(config_name, value)
raise "config settings can only be set via config file" unless Rails.env.test?
@@yaml_cache[config_name] ||= {}
@@yaml_cache[config_name][Rails.env] = value
ConfigFile.stub(config_name, value)
end
def self.from_config(config_name, with_rails_env=:current)
with_rails_env = Rails.env if with_rails_env == :current
if @@yaml_cache[config_name] # if the config wasn't found it'll try again
return @@yaml_cache[config_name] if !with_rails_env
return @@yaml_cache[config_name][with_rails_env]
end
config = nil
path = File.join(Rails.root, 'config', "#{config_name}.yml")
if File.exists?(path)
if Rails.env.test?
config_string = ERB.new(File.read(path))
config = YAML.load(config_string.result)
else
config = YAML.load_file(path)
end
if config.respond_to?(:with_indifferent_access)
config = config.with_indifferent_access
else
config = nil
end
end
@@yaml_cache[config_name] = config
config = config[with_rails_env] if config && with_rails_env
config
ConfigFile.load(config_name, with_rails_env)
end
end

View File

@ -1,6 +1,6 @@
# Initialize canvas statsd configuration. See config/statsd.yml.example.
settings = Setting.from_config("statsd") || {}
settings = ConfigFile.load("statsd") || {}
Rails.configuration.to_prepare do
CanvasStatsd.settings = settings

View File

@ -1,6 +1,6 @@
config = {
:backend => 'active_record',
}.merge((Setting.from_config('delayed_jobs') || {}).symbolize_keys)
}.merge((ConfigFile.load('delayed_jobs') || {}).symbolize_keys)
case config[:backend]
when 'active_record'

View File

@ -1,5 +1,5 @@
GoogleDocs::Connection.config = Proc.new do
Canvas::Plugin.find(:google_docs).try(:settings) || Setting.from_config('google_docs')
Canvas::Plugin.find(:google_docs).try(:settings) || ConfigFile.load('google_docs')
end
GoogleDocs::Entry.extension_looker_upper = ScribdMimeType

View File

@ -1,6 +1,6 @@
# Initialize incoming email configuration. See config/incoming_mail.yml.example.
config = Setting.from_config("incoming_mail") || {}
config = ConfigFile.load("incoming_mail") || {}
Rails.configuration.to_prepare do
IncomingMailProcessor::IncomingMessageProcessor.configure(config)

View File

@ -1,3 +1,3 @@
LinkedIn::Connection.config = Proc.new do
Canvas::Plugin.find(:linked_in).try(:settings) || Setting.from_config('linked_in')
Canvas::Plugin.find(:linked_in).try(:settings) || ConfigFile.load('linked_in')
end

View File

@ -1,6 +1,6 @@
require_dependency 'setting'
config = Setting.from_config('marginalia') || {}
config = ConfigFile.load('marginalia') || {}
if config[:components].present?
require 'marginalia'

View File

@ -7,7 +7,7 @@ require 'net/smtp'
config = {
:domain => "unknowndomain.example.com",
:delivery_method => :smtp,
}.merge((Setting.from_config("outgoing_mail") || {}).symbolize_keys)
}.merge((ConfigFile.load("outgoing_mail") || {}).symbolize_keys)
[:authentication, :delivery_method].each do |key|
config[key] = config[key].to_sym if config.has_key?(key)

View File

@ -8,7 +8,7 @@ config = {
:key => '_normandy_session',
:session_store => :encrypted_cookie_store,
:secret => (Setting.get_or_set("session_secret_key", SecureRandom.hex(64)) rescue SecureRandom.hex(64))
}.merge((Setting.from_config("session_store") || {}).symbolize_keys)
}.merge((ConfigFile.load("session_store") || {}).symbolize_keys)
# :expire_after is the "true" option, and :expires is a legacy option, but is applied
# to the cookie after :expire_after is, so by setting it to nil, we force the lesser
@ -23,13 +23,13 @@ case session_store
when :mem_cache_store
require 'memcache'
config[:namespace] ||= config[:key]
servers = config[:memcache_servers] || Setting.from_config("memcache") || ['localhost:11211']
servers = config[:memcache_servers] || ConfigFile.load("memcache") || ['localhost:11211']
config[:cache] ||= MemCache.new(servers, config)
when :redis_session_store
Bundler.require 'redis'
config[:key_prefix] ||= config[:key]
config[:servers] ||= config[:redis_servers] if config[:redis_servers]
redis_config = Setting.from_config("redis")
redis_config = ConfigFile.load("redis")
if redis_config
config.reverse_merge!(redis_config.symbolize_keys)
end

View File

@ -1,3 +1,3 @@
Twitter::Connection.config = Proc.new do
Canvas::Plugin.find(:twitter).try(:settings) || Setting.from_config('twitter')
Canvas::Plugin.find(:twitter).try(:settings) || ConfigFile.load('twitter')
end

View File

@ -11,7 +11,7 @@
session_store = CANVAS_RAILS2 ? ActionController::Base.session_store : Rails.configuration.session_store
if session_store == ActiveRecord::SessionStore
expire_after = (Setting.from_config("session_store") || {})[:expire_after]
expire_after = (ConfigFile.load("session_store") || {})[:expire_after]
expire_after ||= 1.day
Delayed::Periodic.cron 'ActiveRecord::SessionStore::Session.delete_all', '*/5 * * * *' do
@ -21,7 +21,7 @@ if session_store == ActiveRecord::SessionStore
end
end
persistence_token_expire_after = (Setting.from_config("session_store") || {})[:expire_remember_me_after]
persistence_token_expire_after = (ConfigFile.load("session_store") || {})[:expire_remember_me_after]
persistence_token_expire_after ||= 1.month
Delayed::Periodic.cron 'SessionPersistenceToken.delete_all', '35 11 * * *' do
Shard.with_each_shard(exception: -> { ErrorReport.log_exception(:periodic_job, $!) }) do

View File

@ -5,7 +5,7 @@ class SetSamlEntityId < ActiveRecord::Migration
# All future new SAML configs will use the host of the account
def self.up
old_default_domain = nil
if app_config = Setting.from_config('saml')
if app_config = ConfigFile.load('saml')
old_default_domain = app_config[:entity_id]
end

View File

@ -31,7 +31,7 @@ describe "execute and update" do
YAML.load(ERB.new(File.read(config_path)).result)['test']
end
let(:db) do
# TODO: Setting.from_config really deserves to be its own Config component that we could use here
# TODO: ConfigFile.load really deserves to be its own Config component that we could use here
test_config = YAML.load(ERB.new(File.read(config_path)).result)['test']['page_views']
CanvasCassandra::Database.new("test_conn", test_config['servers'], {keyspace: test_config['keyspace'], cql_version: '3.0.0'}, TestLogger.new)
end

View File

@ -23,7 +23,7 @@ module Canvas
def self.redis
raise "Redis is not enabled for this install" unless Canvas.redis_enabled?
@redis ||= begin
settings = Setting.from_config('redis')
settings = ConfigFile.load('redis')
Canvas::RedisConfig.from_settings(settings).redis
end
end
@ -36,7 +36,7 @@ module Canvas
end
def self.redis_enabled?
@redis_enabled ||= Setting.from_config('redis').present?
@redis_enabled ||= ConfigFile.load('redis').present?
end
def self.reconnect_redis
@ -57,10 +57,10 @@ module Canvas
unless @cache_stores
# this method is called really early in the bootup process, and
# autoloading might not be available yet, so we need to manually require
# Setting
require_dependency 'app/models/setting'
# Config
require_dependency 'lib/config_file'
@cache_stores = {}
configs = Setting.from_config('cache_store', nil) || {}
configs = ConfigFile.load('cache_store', nil) || {}
# sanity check the file
unless configs.is_a?(Hash)
@ -77,7 +77,7 @@ module Canvas
case config.delete('cache_store')
when 'mem_cache_store'
config['namespace'] ||= config['key']
servers = config['servers'] || (Setting.from_config('memcache', env))
servers = config['servers'] || (ConfigFile.load('memcache', env))
if servers
@cache_stores[env] = :mem_cache_store, servers, config
end
@ -89,7 +89,7 @@ module Canvas
#
# the only options currently supported in redis-cache are the list of
# servers, not key prefix or database names.
config = (Setting.from_config('redis', env) || {}).merge(config)
config = (ConfigFile.load('redis', env) || {}).merge(config)
config['key_prefix'] ||= config['key']
servers = config['servers']
@cache_stores[env] = :redis_store, servers

View File

@ -3,7 +3,7 @@ module Canvas
module DatabaseBuilder
def self.configured?(config_name, environment = :current)
raise ArgumentError, "config name required" if config_name.blank?
config = Setting.from_config('cassandra', environment)
config = ConfigFile.load('cassandra', environment)
config = config && config[config_name]
config && config['servers'] && config['keyspace']
end
@ -13,7 +13,7 @@ module Canvas
environment = Rails.env if environment == :current
key = [config_name, environment]
@connections.fetch(key) do
config = Setting.from_config('cassandra', environment)
config = ConfigFile.load('cassandra', environment)
config = config && config[config_name]
unless config
@connections[key] = nil
@ -34,7 +34,7 @@ module Canvas
end
def self.config_names
Setting.from_config('cassandra').try(:keys) || []
ConfigFile.load('cassandra').try(:keys) || []
end
def self.read_consistency_setting(database_name = nil)

View File

@ -43,7 +43,7 @@ class Migrator
end
end
config = Setting.from_config('external_migration') || {}
config = ConfigFile.load('external_migration') || {}
@unzipped_file_path = Dir.mktmpdir(migration_type.to_s, config[:data_folder].presence)
@base_export_dir = @settings[:base_download_dir] || find_export_dir
@course[:export_folder_path] = File.expand_path(@base_export_dir)

View File

@ -122,7 +122,7 @@ module MigratorHelper
end
def create_export_dir(slug)
config = Setting.from_config('external_migration')
config = ConfigFile.load('external_migration')
if config && config[:data_folder]
folder = config[:data_folder]
else
@ -150,7 +150,7 @@ module MigratorHelper
end
def self.download_archive(settings)
config = Setting.from_config('external_migration') || {}
config = ConfigFile.load('external_migration') || {}
if settings[:export_archive_path]
settings[:archive_file] = File.open(settings[:export_archive_path], 'rb')
elsif settings[:course_archive_download_url].present?

View File

@ -73,7 +73,7 @@ module Canvas::Migration::Worker
def self.clear_exported_data(folder)
begin
config = Setting.from_config('external_migration')
config = ConfigFile.load('external_migration')
if !config || !config[:keep_after_complete]
FileUtils::rm_rf(folder) if File.exists?(folder)
end

View File

@ -35,7 +35,7 @@ module CC
@zip_file = nil
@zip_name = nil
@logger = Rails.logger
@migration_config = Setting.from_config('external_migration')
@migration_config = ConfigFile.load('external_migration')
@migration_config ||= {:keep_after_complete => false}
@for_course_copy = opts[:for_course_copy]
@qti_only_export = @content_export && @content_export.qti_export?

View File

@ -223,7 +223,7 @@ module CCHelper
protocol = HostUrl.protocol
host = HostUrl.context_host(@course)
port = Setting.from_config("domain").try(:[], :domain).try(:split, ':').try(:[], 1)
port = ConfigFile.load("domain").try(:[], :domain).try(:split, ':').try(:[], 1)
@url_prefix = "#{protocol}://#{host}"
@url_prefix += ":#{port}" if !host.include?(':') && port.present?
end

61
lib/config_file.rb Normal file
View File

@ -0,0 +1,61 @@
#
# Copyright (C) 2011-2014 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
module ConfigFile
@@yaml_cache = {}
def self.unstub
@@yaml_cache = {}
end
def self.stub(config_name, value)
raise "config settings can only be set via config file" unless Rails.env.test?
@@yaml_cache[config_name] ||= {}
@@yaml_cache[config_name][Rails.env] = value
end
def self.load(config_name, with_rails_env=:current)
with_rails_env = Rails.env if with_rails_env == :current
if @@yaml_cache[config_name] # if the config wasn't found it'll try again
return @@yaml_cache[config_name] if !with_rails_env
return @@yaml_cache[config_name][with_rails_env]
end
config = nil
path = File.join(Rails.root, 'config', "#{config_name}.yml")
if File.exists?(path)
if Rails.env.test?
config_string = ERB.new(File.read(path))
config = YAML.load(config_string.result)
else
config = YAML.load_file(path)
end
if config.respond_to?(:with_indifferent_access)
config = config.with_indifferent_access
else
config = nil
end
end
@@yaml_cache[config_name] = config
config = config[with_rails_env] if config && with_rails_env
config
end
end

View File

@ -48,7 +48,7 @@ class CutyCapt
def self.config
return @@config if defined?(@@config) && @@config
setting = (Setting.from_config('cutycapt') || {}).symbolize_keys
setting = (ConfigFile.load('cutycapt') || {}).symbolize_keys
@@config = CUTYCAPT_DEFAULTS.merge(setting).with_indifferent_access
self.process_config
@@config = nil unless @@config[:path]

View File

@ -31,7 +31,7 @@ class HostUrl
def domain_config
if !@@domain_config
@@domain_config = Setting.from_config("domain")
@@domain_config = ConfigFile.load("domain")
@@domain_config ||= {}
end
@@domain_config

View File

@ -247,7 +247,7 @@ describe "API Authentication", type: :request do
it "should execute for saml login" do
pending("requires SAML extension") unless AccountAuthorizationConfig.saml_enabled
Setting.set_config("saml", {})
ConfigFile.stub('saml', {})
account = account_with_saml(:account => Account.default)
flow do
Onelogin::Saml::Response.any_instance.stubs(:settings=)

View File

@ -215,7 +215,7 @@ describe PseudonymSessionsController do
end
it "should scope logins to the correct domain root account" do
Setting.set_config("saml", {})
ConfigFile.stub('saml', {})
unique_id = 'foo@example.com'
account1 = account_with_saml
@ -250,8 +250,6 @@ describe PseudonymSessionsController do
response.should redirect_to(dashboard_url(:login_success => 1))
session[:saml_unique_id].should == unique_id
Pseudonym.find(session['pseudonym_credentials_id']).should == user2.pseudonyms.first
Setting.set_config("saml", nil)
end
context "multiple authorization configs" do
@ -461,7 +459,7 @@ describe PseudonymSessionsController do
context "login attributes" do
before(:each) do
Setting.set_config("saml", {})
ConfigFile.stub('saml', {})
@unique_id = 'foo'
@account = account_with_saml
@ -505,7 +503,7 @@ describe PseudonymSessionsController do
end
it "should use the eppn saml attribute if configured" do
Setting.set_config("saml", {})
ConfigFile.stub('saml', {})
unique_id = 'foo'
account = account_with_saml
@ -531,7 +529,7 @@ describe PseudonymSessionsController do
end
it "should redirect to RelayState relative urls" do
Setting.set_config("saml", {})
ConfigFile.stub('saml', {})
unique_id = 'foo@example.com'
account = account_with_saml
@ -550,7 +548,7 @@ describe PseudonymSessionsController do
end
it "should decode an actual saml response" do
Setting.set_config("saml", {})
ConfigFile.stub('saml', {})
unique_id = 'student@example.edu'
account_with_saml

View File

@ -23,7 +23,7 @@ describe AccountsController do
context "SAML meta data" do
before(:each) do
pending("requires SAML extension") unless AccountAuthorizationConfig.saml_enabled
Setting.set_config('saml', {
ConfigFile.stub('saml', {
:tech_contact_name => nil,
:tech_contact_email => nil
})

View File

@ -25,7 +25,7 @@ describe CutyCapt do
context "configuration" do
it "should correctly look up parameters specified by string keys in the config" do
Setting.set_config("cutycapt", { "path" => 'not used', 'timeout' => 1000 })
ConfigFile.stub('cutycapt', { "path" => 'not used', 'timeout' => 1000 })
CutyCapt.config[:path].should == "not used"
CutyCapt.config[:timeout].should == 1000
end
@ -33,14 +33,14 @@ describe CutyCapt do
context "url validation" do
it "should check for an http scheme" do
Setting.set_config("cutycapt", { :path => 'not used' })
ConfigFile.stub('cutycapt', { :path => 'not used' })
CutyCapt.verify_url("ftp://example.com/").should be_false
CutyCapt.verify_url("http://example.com/").should be_true
CutyCapt.verify_url("https://example.com/").should be_true
end
it "should check for blacklisted domains" do
Setting.set_config("cutycapt", { :path => 'not used', :domain_blacklist => ['example.com'] })
ConfigFile.stub('cutycapt', { :path => 'not used', :domain_blacklist => ['example.com'] })
CutyCapt.verify_url("http://example.com/blah").should be_false
CutyCapt.verify_url("http://foo.example.com/blah").should be_false
@ -49,7 +49,7 @@ describe CutyCapt do
end
it "should check for blacklisted ip blocks" do
Setting.set_config("cutycapt", { :path => 'not used' })
ConfigFile.stub('cutycapt', { :path => 'not used' })
CutyCapt.verify_url("http://10.0.1.1/blah").should be_false
CutyCapt.verify_url("http://169.254.169.254/blah").should be_false
@ -62,7 +62,7 @@ describe CutyCapt do
context "execution" do
it "should time out cuty processes" do
Setting.set_config("cutycapt", { :path => '/bin/sleep', :timeout => '1000' })
ConfigFile.stub('cutycapt', { :path => '/bin/sleep', :timeout => '1000' })
CutyCapt.stubs(:cuty_arguments).returns([ "/bin/sleep", "60" ])
begin

View File

@ -21,16 +21,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe 'HostUrl' do
describe "protocol" do
it "should return https if domain config says ssl" do
Setting.expects(:from_config).with("domain").returns({})
ConfigFile.expects(:load).with("domain").returns({})
Attachment.stubs(:file_store_config).returns({})
HostUrl.protocol.should == 'http'
HostUrl.reset_cache!
Setting.expects(:from_config).with("domain").returns('ssl' => true)
ConfigFile.expects(:load).with("domain").returns('ssl' => true)
HostUrl.protocol.should == 'https'
end
it "should return https if file store config says secure" do
Setting.stubs(:from_config).with("domain").returns({})
ConfigFile.stubs(:load).with("domain").returns({})
Attachment.stubs(:file_store_config).returns('secure' => true)
HostUrl.protocol.should == 'https'
end

View File

@ -21,7 +21,7 @@ require 'db/migrate/20120106220543_set_saml_entity_id'
describe 'SetSamlEntityId' do
before(:each) do
Setting.set_config('saml', {
ConfigFile.stub('saml', {
:entity_id => "http://watup_fool.com/saml2"
})
HostUrl.stubs(:default_host).returns('bob.cody.instructure.com')
@ -48,7 +48,7 @@ describe 'SetSamlEntityId' do
end
it "should use the account's domain if no config is set" do
Setting.set_config('saml', {
ConfigFile.stub('saml', {
:entity_id => nil
})

View File

@ -69,7 +69,7 @@ describe AccountAuthorizationConfig do
end
it "should load encryption settings" do
Setting.set_config('saml', {
ConfigFile.stub('saml', {
:entity_id => 'http://www.example.com/saml2',
:encryption => {
:private_key => @file_that_exists,
@ -83,7 +83,7 @@ describe AccountAuthorizationConfig do
end
it "should load the tech contact settings" do
Setting.set_config('saml', {
ConfigFile.stub('saml', {
:tech_contact_name => 'Admin Dude',
:tech_contact_email => 'admindude@example.com',
})
@ -95,7 +95,7 @@ describe AccountAuthorizationConfig do
end
it "should allow additional private keys to be set" do
Setting.set_config('saml', {
ConfigFile.stub('saml', {
:entity_id => 'http://www.example.com/saml2',
:encryption => {
:private_key => @file_that_exists,
@ -113,7 +113,7 @@ describe AccountAuthorizationConfig do
it "should allow some additional private keys to be set when not all exist" do
file_that_does_not_exist = '/tmp/i_am_not_a_private_key'
Setting.set_config('saml', {
ConfigFile.stub('saml', {
:entity_id => 'http://www.example.com/saml2',
:encryption => {
:private_key => @file_that_exists,

View File

@ -24,7 +24,7 @@ require 'coffee-script'
require File.expand_path(File.dirname(__FILE__) + '/helpers/custom_selenium_rspec_matchers')
include I18nUtilities
SELENIUM_CONFIG = Setting.from_config("selenium") || {}
SELENIUM_CONFIG = ConfigFile.load("selenium") || {}
SERVER_IP = SELENIUM_CONFIG[:server_ip] || UDPSocket.open { |s| s.connect('8.8.8.8', 1); s.addr.last }
BIND_ADDRESS = SELENIUM_CONFIG[:bind_address] || '0.0.0.0'
SECONDS_UNTIL_COUNTDOWN = 5

View File

@ -433,6 +433,7 @@ end
Time.zone = 'UTC'
Account.clear_special_account_cache!
Setting.reset_cache!
ConfigFile.unstub
HostUrl.reset_cache!
Notification.reset_cache!
ActiveRecord::Base.reset_any_instantiation!

View File

@ -17,7 +17,7 @@ class Periodic
# throws an error if any cron override in config/periodic_jobs.yml is invalid
def self.audit_overrides!
overrides = Setting.from_config('periodic_jobs') || {}
overrides = ConfigFile.load('periodic_jobs') || {}
overrides.each do |name, cron_line|
# throws error if the line is malformed
Rufus::CronLine.new(cron_line)
@ -32,7 +32,7 @@ class Periodic
def self.cron(job_name, cron_line, job_args = {}, &block)
raise ArgumentError, "job #{job_name} already scheduled!" if self.scheduled[job_name]
override = (Setting.from_config('periodic_jobs') || {})[job_name]
override = (ConfigFile.load('periodic_jobs') || {})[job_name]
cron_line = override if override
self.scheduled[job_name] = self.new(job_name, cron_line, job_args, block)
end

View File

@ -435,7 +435,7 @@ shared_examples_for 'a backend' do
end
it "should allow overriding schedules using periodic_jobs.yml" do
Setting.set_config('periodic_jobs', { 'my ChangedJob' => '*/10 * * * * *' })
ConfigFile.stub('periodic_jobs', { 'my ChangedJob' => '*/10 * * * * *' })
Delayed::Periodic.scheduled = {}
Delayed::Periodic.cron('my ChangedJob', '*/5 * * * * *') do
Delayed::Job.enqueue(SimpleJob.new)
@ -445,7 +445,7 @@ shared_examples_for 'a backend' do
end
it "should fail if the override cron line is invalid" do
Setting.set_config('periodic_jobs', { 'my ChangedJob' => '*/10 * * * * * *' }) # extra asterisk
ConfigFile.stub('periodic_jobs', { 'my ChangedJob' => '*/10 * * * * * *' }) # extra asterisk
Delayed::Periodic.scheduled = {}
expect { Delayed::Periodic.cron('my ChangedJob', '*/5 * * * * *') do
Delayed::Job.enqueue(SimpleJob.new)