Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.
3 changes: 0 additions & 3 deletions config/env.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 2 additions & 11 deletions lua/concurredis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 7 additions & 36 deletions lua/crontab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand All @@ -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()
Expand All @@ -387,7 +359,6 @@ end

crontab.stats = function()
return {
disabled = crontab.disabled and 1 or 0,
timers = #TIMERS,
jobs = get_jobs()
}
Expand Down
2 changes: 1 addition & 1 deletion lua/models/system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down