8000 Add sensible default is_expired functions · Issue #137 · tarantool/expirationd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Add sensible default is_expired functions #137
Open
@WeCodingNow

Description

@WeCodingNow

Right now is_tuple_expired (is_expired in cartridge role configuration) is a required argument when configuring an expirationd worker
It must be a name of a function in _G.

Right now the problem is that there is at all a need to code such functions for the developers of an app.
What if you don't wan't to develop an app, but rather want to deploy a default cartridge cluster (just straight up create -> pack -> deploy) that has everything else you need provided via other modules, and configure it? In other words, a full out-of-the-box experience.
A configuration like this:

  • ddl/migrations for applying schema
  • crud for data access
  • expirationd (??? need to write own role that goes together with expirer OR write code in init.lua)

How about implementing a bunch of such functions that are provided by defalut?
Something like

local M = {}

local fiber = require('fiber')

function M.check_ttl(args, tuple)
    local now = fiber.time()
    local ttl = tuple[args.ttl_field]
    local timestamp = tuple[args.timestamp_field]

    if (ttl == nil or timestamp == nil) then
        return false
    end

    return now > timestamp + ttl
end

function M.check_time_to_remove(args, tuple)
-- same thing, but for tuples
-- that only have a "time to expire" timestamp, instead of the "creation time + ttl" combo
end

return M

...
-- somewhere in expirationd
for f_name, f in pairs(require('expirationd.functions') do
    rawset(_G, '__'..f_name, f) 
end

So the possible expirationd.yml configuration would look like:

# tasks
expire_at:
  space: session
  is_expired: __check_ttl
  options:
    args:
      ttl_field: max_inactive_interval
      timestamp_field: last_accessed_time
  is_master_only: true

With no need to code anything in cartridge init.lua or in a custom role

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0