Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to keep the ttl while releasing the task #149

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ Example: queue.tube.list_of_sites:release(15, {delay=10})
Note: in the above example, the delay option means
"the task cannot be executed again for 10 seconds".

Example: queue.tube.list_of_sites:release(15, {delay=10, keep_ttl=true})

Note: in the above example, the delay option means
"the task cannot be executed again for 10 seconds" and
the associated keep_ttl option means "the task ttl stays unchanged"

## Peeking at a task

```lua
Expand Down
11 changes: 8 additions & 3 deletions queue/abstract/driver/fifottl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,16 @@ function method.release(self, id, opts)
return
end
if opts.delay ~= nil and opts.delay > 0 then
task = self.space:update(id, {
local upd = {
{ '=', i_status, state.DELAYED },
{ '=', i_next_event, util.event_time(opts.delay) },
{ '=', i_next_event, util.event_time(opts.delay) }
}
if not opts.keep_ttl then
table.insert(upd,
{ '+', i_ttl, util.time(opts.delay) }
})
)
end
task = self.space:update(id, upd)
else
task = self.space:update(id, {
{ '=', i_status, state.READY },
Expand Down
11 changes: 8 additions & 3 deletions queue/abstract/driver/utubettl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,16 @@ function method.release(self, id, opts)
return
end
if opts.delay ~= nil and opts.delay > 0 then
task = self.space:update(id, {
local upd = {
{ '=', i_status, state.DELAYED },
{ '=', i_next_event, util.event_time(opts.delay) },
{ '=', i_next_event, util.event_time(opts.delay) }
}
if not opts.keep_ttl then
table.insert(upd,
{ '+', i_ttl, util.time(opts.delay) }
})
)
end
task = self.space:update(id, upd)
if task ~= nil then
return process_neighbour(self, task, 'release')
end
Expand Down
17 changes: 16 additions & 1 deletion t/020-fifottl.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local fiber = require('fiber')

local test = require('tap').test()
test:plan(16)
test:plan(17)

local queue = require('queue')
local state = require('queue.abstract.state')
Expand Down Expand Up @@ -245,6 +245,21 @@ test:test('ttl after delay test', function(test)
test:is(task.ttr, TTR * 1000000, 'check TTR after release')
end)

test:test('ttl after delay test with keep_ttl', function(test)
local TTL = 10
local TTR = 20
local DELTA = 5
test:plan(2)
box.cfg{}
local tube = queue.create_tube('test_ttl_release_keep', 'fifottl', { if_not_exists = true })
tube:put({'test_task'}, { ttl = TTL, ttr = TTR })
tube:take()
tube:release(0, { delay = DELTA, keep_ttl = true })
local task = box.space.test_ttl_release_keep:get(0)
test:is(task.ttl, TTL * 1000000, 'check TTL after release')
test:is(task.ttr, TTR * 1000000, 'check TTR after release')
end)

-- gh-96: infinite loop after dropping a tube with a burried task
test:test('buried task in a dropped queue', function(test)
test:plan(1)
Expand Down
20 changes: 19 additions & 1 deletion t/040-utubettl.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local yaml = require('yaml')
local fiber = require('fiber')

local test = (require('tap')).test()
test:plan(17)
test:plan(18)

local queue = require('queue')
local state = require('queue.abstract.state')
Expand Down Expand Up @@ -203,6 +203,24 @@ test:test('release[delay] in utube', function(test)
test:is(state, 2, 'state was changed')
end)

test:test('release[delay, keep_ttl] in utube', function(test)
test:plan(5)
local TTL = 10
local DELAY = 5

test:ok(tube:put(123, {utube = 'fgh', ttl = TTL}), 'task was put')
local taken = tube:take()
test:ok(taken, 'task was taken ' .. taken[1])
test:is(taken[3], 123, 'task.data')
tube:release(taken[1], { delay = DELAY, keep_ttl = true })
local task = box.space.test:get(taken[1])
test:is(task.ttl, TTL * 1000000, 'check TTL with keep_ttl after release')
tube:take()
tube:release(taken[1], {delay = DELAY})
task = box.space.test:get(taken[1])
test:is(task.ttl, (TTL + DELAY) * 1000000, 'check TTL without keep_ttl after release')
end)

test:test('if_not_exists test', function(test)
test:plan(2)
local tube = queue.create_tube('test_ine', 'utubettl', {
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ VERSION=${VERSION:-2_2}

curl -sfL https://packagecloud.io/tarantool/${VERSION}/gpgkey | sudo apt-key add -
release=`lsb_release -c -s`
release='focal'

sudo apt-get install -y apt-transport-https

Expand Down