diff --git a/config/env.conf b/config/env.conf index 5a7dca4..4875fb9 100644 --- a/config/env.conf +++ b/config/env.conf @@ -4,11 +4,8 @@ env SLUG_ENV; env SLUG_LOGFILE; -env SLUG_DISABLE_CRON; env SLUG_DISABLE_CACHE; -env SLUG_CRON_FORCED; - env SLUG_CSRF_PROTECTION; env SLUG_BRAIN_HOST; diff --git a/lua/concurredis.lua b/lua/concurredis.lua index b1a98f3..4c01d8b 100644 --- a/lua/concurredis.lua +++ b/lua/concurredis.lua @@ -176,20 +176,11 @@ end concurredis.execute = function(f) - local first_connection = false - if not ngx.ctx.red then - ngx.ctx.red = concurredis.connect() - first_connection = true - end - - local red = ngx.ctx.red + local red = concurredis.connect() local result = { error_handler.execute(function() return f(red) end) } - if first_connection then - red:set_keepalive(KEEPALIVE_TIMEOUT, POOL_SIZE) - ngx.ctx.red = nil - end + red:set_keepalive(KEEPALIVE_TIMEOUT, POOL_SIZE) local ok, err = result[1], result[2] if ok then diff --git a/lua/crontab.lua b/lua/crontab.lua index 6e3dc5a..25bc24d 100644 --- a/lua/crontab.lua +++ b/lua/crontab.lua @@ -144,7 +144,7 @@ local TIMERS = { } local TIMERS_DICT = {} -for _,timer in ipairs(TIMERS) do TIMERS_DICT[timer.id] = true end +for _,timer in ipairs(TIMERS) do TIMERS_DICT[timer.id] = timer end local dict = ngx.shared.crontab @@ -296,10 +296,6 @@ crontab.randomizer = function(timer) end crontab.initialize = function() - crontab.enable() - - if crontab.disabled then return end - -- it wont run initialize when locked crontab.block(function() ngx.log(ngx.INFO, '[cron] initializing') @@ -327,35 +323,18 @@ crontab.flush = function() end) end -crontab.timer = function(id) - for _,timer in ipairs(TIMERS) do - if timer.id == id then return timer end - end -end - -local has_slug_name = function() - local Config = require 'models.config' - return Config.get_slug_name() -end - -crontab.enabled = function() - return not crontab.disabled and (crontab.forced or has_slug_name()) +crontab.get_timer = function(id) + return TIMERS_DICT[id] end crontab.run = function(timer, job_id) ngx.log(ngx.INFO, '[cron] running ' .. timer.id .. ' job ' .. job_id) - local forced = job_id == 'forced' or job_id == 'manual' - - if forced or crontab.enabled() then - crontab.lock(function() - statsd.timer('cron.' .. timer.id, function() - error_handler.execute(timer.action) - end) + crontab.lock(function() + statsd.timer('cron.' .. timer.id, function() + error_handler.execute(timer.action) end) - else - ngx.log(ngx.INFO, '[cron] skipping run of ' .. timer.id .. ' job ' .. job_id .. ': slug name not set' ) - end + end) ngx.log(ngx.INFO, '[cron] finished ' .. timer.id .. ' job ' .. job_id) @@ -368,17 +347,10 @@ crontab.shutdown = function() end crontab.halt = function() - crontab.disabled = true - crontab.forced = false dict:flush_all() dict:flush_expired() end -crontab.enable = function() - crontab.disabled = os.getenv('SLUG_DISABLE_CRON') - crontab.forced = os.getenv('SLUG_CRON_FORCED') -end - crontab.reset = function() ngx.log(ngx.INFO, 'crontab reset') crontab.halt() @@ -387,7 +359,6 @@ end crontab.stats = function() return { - disabled = crontab.disabled and 1 or 0, timers = #TIMERS, jobs = get_jobs() } diff --git a/lua/models/system.lua b/lua/models/system.lua index f7500ed..e83801a 100644 --- a/lua/models/system.lua +++ b/lua/models/system.lua @@ -71,7 +71,7 @@ System.log = function(block) end System.run_timer = function(timer_id) - local timer = crontab.timer(timer_id) + local timer = crontab.get_timer(timer_id) if timer then crontab.run(timer, 'manual')