Last active
March 21, 2018 13:59
-
-
Save mumez/8bb2620ffac1912dd02e1706d800b58d to your computer and use it in GitHub Desktop.
Tarantool initialization file with expirationd setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Modules | |
console = require('console') | |
queue = require('queue') | |
http = require('http.client') | |
json = require('json') | |
-- Expirationd setup | |
expirationd = require('expirationd') | |
function is_expired(args, tuple) | |
local expire_secs = tuple[3] or 0 | |
return (expire_secs - os.time() < 0) | |
end | |
function start_cleaner(space_name) | |
if (box.space[space_name]) then | |
if (box.space[space_name].index) then | |
expirationd.start(space_name..'_cleaner', space_name, is_expired, {}) | |
end | |
end | |
end | |
function start_cleaners() | |
local table_names = box.space._space.index.name:select('zzz_exp',{iterator=box.index.GE}) | |
for k,v in ipairs(table_names) do | |
local tb_name = v[3] | |
start_cleaner(tb_name) | |
end | |
end | |
-- Startup | |
box.cfg{listen = 3301} | |
-- User Roles | |
box.schema.user.create('taran', {password = 'talk',if_not_exists = true}) | |
box.schema.user.grant('taran', 'read,write,execute', 'universe', nil, {if_not_exists = true}) | |
-- Initializer | |
start_cleaners() | |
console.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment