Skip to content

Commit e20a89d

Browse files
zloidemonLeonidVas
authored andcommitted
add iteration and full scan delays to a task
Added the ability to set iteration and full scan delays for a task. iteration delay - max sleep time between iterations (in seconds). full scan delay - sleep time between full scans (in seconds). Related to #38
1 parent da75bd6 commit e20a89d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ opt
4444
* `args` - passed to `is_tuple_expired()` and `process_expired_tuple()` as additional context
4545
* `tuples_per_iteration` - number of tuples will be checked by one iteration
4646
* `full_scan_time` - time required for full index scan (in seconds)
47+
* `iteration_delay` - max sleep time between iterations (in seconds)
48+
* `full_scan_delay` - sleep time between full scans (in seconds)
4749
* `force` - run, even on replica
4850

4951
### `expirationd.kill (name)`

expirationd.lua

+21-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ end
7171

7272
local function suspend_basic(scan_space, task, len)
7373
local delay = (task.tuples_per_iteration * task.full_scan_time)
74-
delay = math.min(delay / len, constants.max_delay)
74+
delay = math.min(delay / len, task.iteration_delay)
7575
fiber.sleep(delay)
7676
end
7777

@@ -163,8 +163,8 @@ local function worker_loop(task)
163163
task.do_worker_iteration(task)
164164
end
165165

166-
-- iteration is complete, yield
167-
fiber.sleep(constants.max_delay)
166+
-- Full scan iteration is complete, yield
167+
fiber.sleep(task.full_scan_delay)
168168
end
169169
end
170170

@@ -247,6 +247,8 @@ local function create_task(name)
247247
is_tuple_expired = nil,
248248
process_expired_tuple = nil,
249249
args = nil,
250+
iteration_delay = constants.max_delay,
251+
full_scan_delay = constants.max_delay,
250252
tuples_per_iteration = constants.default_tuples_per_iteration,
251253
full_scan_time = constants.default_full_scan_time,
252254
vinyl_assumed_space_len = constants.default_vinyl_assumed_space_len,
@@ -293,6 +295,8 @@ end
293295
-- process_expired_tuple() as additional context
294296
-- * tuples_per_iteration -- number of tuples will be checked by one iteration
295297
-- * full_scan_time -- time required for full index scan (in seconds)
298+
-- * iteration_delay -- max sleep time between iterations (in seconds)
299+
-- * full_scan_delay -- sleep time between full scans (in seconds)
296300
-- * force -- run task even on replica
297301
-- }
298302
local function expirationd_run_task(name, space_id, is_tuple_expired, options)
@@ -380,6 +384,20 @@ local function expirationd_run_task(name, space_id, is_tuple_expired, options)
380384
task.do_worker_iteration = default_do_worker_iteration
381385
end
382386

387+
if options.iteration_delay ~= nil then
388+
if type(options.iteration_delay) ~= 'number' then
389+
error("invalid type of iteration_delay value")
390+
end
391+
task.iteration_delay = options.iteration_delay
392+
end
393+
394+
if options.full_scan_delay ~= nil then
395+
if type(options.full_scan_delay) ~= 'number' then
396+
error("invalid type of full_scan_delay value")
397+
end
398+
task.full_scan_delay = options.full_scan_delay
399+
end
400+
383401
-- put the task to table
384402
task_list[name] = task
385403
-- run

0 commit comments

Comments
 (0)