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

Conversation

qdrin
Copy link

@qdrin qdrin commented Apr 19, 2021

Adds the option 'touch_ttl' that is assotiated with delay option in the release method of fifottl. Allows keep the task ttl unchanged when it necessary. Might help with retries.

…he release method of fifottl. Allows keep the task ttl unchanged when it necessary
Comment on lines 303 to 314
if opts.touch_ttl == nil then opts.touch_ttl = true 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 opts.touch_ttl then
table.insert(upd,
{ '+', i_ttl, util.time(opts.delay) }
})
)
end
task = self.space:update(id, upd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name a new option in a way to make its default value false: say, keep_ttl. It looks more natural for me.

I guess the code hunk may be written in a simpler way (didn't tested):

task = self.space:update(id, {
    { '=', i_status, state.DELAYED },
    { '=', i_next_event, util.event_time(opts.delay) },
    not opts.keep_ttl and { '+', i_ttl, util.time(opts.delay) } or nil,
})

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fine advise. Renamed

@@ -300,12 +300,18 @@ function method.release(self, id, opts)
if task == nil then
return
end
if opts.touch_ttl == nil then opts.touch_ttl = true end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to support it in 'utubettl' driver too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in new commit. Thanks for Your idea

@@ -300,12 +300,18 @@ function method.release(self, id, opts)
if task == nil then
return
end
if opts.touch_ttl == nil then opts.touch_ttl = true end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually cover all new functionality with a test. Aren't you mind to add one? They're in the t/ directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered in new commit. Sorry for that

@rybakit
Copy link
Contributor

rybakit commented Apr 21, 2021

IMHO, introducing a new option that solely depends on another option is really not the best solution to the problem. I'm afraid it will be a source of confusion for users, because the API allows the "associated" option to be passed alone and, when allowed, is likely to be misused. So I expect to see in the future something like

t:release(15, {keep_ttl=true})

which makes no sense (however, it gives a false impression that it somehow affects the task ttl). Moreover, when #125 gets implemented, we might get

t:release(15, {delay=10, keep_ttl=true, ttl=10})

which is a valid combination of options, although it looks very weird and confusing.

As an alternative, I would consider adding a new standalone option, something like delay_with_ttl or delay_wo_ttl (or any other name that works best), so at least it can be used alone. Also, we might think of forbidding passing both delay and delay_with_ttl or at least clearly define the precedence of these options.

Another alternative is to introduce a new api method.

@rybakit
Copy link
Contributor

rybakit commented Apr 21, 2021

After thinking more about the issue, I believe it can be solved in the scope of #125. If we had the ability to pass more options to release() we could do

t:release(15, {delay=10, ttl=-1})

where ttl=-1 indicates that we don't want to update ttl.

@qdrin
Copy link
Author

qdrin commented Apr 22, 2021

IMHO, introducing a new option that solely depends on another option is really not the best solution to the problem. I'm afraid it will be a source of confusion for users, because the API allows the "associated" option to be passed alone and, when allowed, is likely to be misused. So I expect to see in the future something like

t:release(15, {keep_ttl=true})

which makes no sense (however, it gives a false impression that it somehow affects the task ttl). Moreover, when #125 gets implemented, we might get

t:release(15, {delay=10, keep_ttl=true, ttl=10})

which is a valid combination of options, although it looks very weird and confusing.

As an alternative, I would consider adding a new standalone option, something like delay_with_ttl or delay_wo_ttl (or any other name that works best), so at least it can be used alone. Also, we might think of forbidding passing both delay and delay_with_ttl or at least clearly define the precedence of these options.

Another alternative is to introduce a new api method.

Perhaps the option is not the best solution. But in the current implementation it doesn't seem confusive as the only case with ttl update is the release.
I agree the #125 is fine and covers much more cases. So it's implementation seems to be more complicated and i suppose deserves the particular driver. Meenwhile my purpose was to give some new uses to current one with minimum efforts.

@LeonidVas
Copy link
Contributor

HI! Thank you for the patch.
I have several questions:

  • Why can't you just use the touch method for this purpose?
  • Could you to describe few use case of the feature?

@qdrin
Copy link
Author

qdrin commented Apr 22, 2021

IMHO, introducing a new option that solely depends on another option is really not the best solution to the problem. I'm afraid it will be a source of confusion for users, because the API allows the "associated" option to be passed alone and, when allowed, is likely to be misused. So I expect to see in the future something like

t:release(15, {keep_ttl=true})

which makes no sense (however, it gives a false impression that it somehow affects the task ttl). Moreover, when #125 gets implemented, we might get

t:release(15, {delay=10, keep_ttl=true, ttl=10})

which is a valid combination of options, although it looks very weird and confusing.

As an alternative, I would consider adding a new standalone option, something like delay_with_ttl or delay_wo_ttl (or any other name that works best), so at least it can be used alone. Also, we might think of forbidding passing both delay and delay_with_ttl or at least clearly define the precedence of these options.

Another alternative is to introduce a new api method.

Perhaps the option is not the best solution. But in the current implementation it doesn't seem confusive as the only case with ttl update is the release.
I agree the #125 is fine and covers much more cases. So it's implementation seems to be more complicated and i suppose deserves the particular driver. Meenwhile my purpose was to give some new uses to current one with minimum efforts.

* Could you to describe few use case of the feature?

My case is to retry failed tasks (http requests) every 30 seconds for 6-minutes period. So I need ttl to be constant. Shure if touch() could decrease ttl it would solve the issue along with "classic" release()

@qdrin qdrin closed this Apr 22, 2021
@qdrin
Copy link
Author

qdrin commented Apr 22, 2021

Sorry it seems i close the request accidently. Let's me reopen

@qdrin qdrin reopened this Apr 22, 2021
@LeonidVas
Copy link
Contributor

LeonidVas commented Apr 23, 2021

My case is to retry failed tasks (http requests) every 30 seconds for 6-minutes period. So I need ttl to be constant. Shure if touch() could decrease ttl it would solve the issue along with "classic" release()

Is it close to ttr = 30 with ttl = 360. Did I understand your case correctly?
Or maybe it's like ttl = 360 and release with delay = 30.

@LeonidVas
Copy link
Contributor

Well, thanks for the PR, but it looks like we haven't decided yet whether such functionality is needed in the module and how exactly the API of this functionality should look like. I think it would be good to resolve these questions in discussion #125, and then start implementing the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants