Skip to content

fix(log-rotate): avoid creating multiple timers#2596

Merged
spacewander merged 4 commits into
apache:masterfrom
spacewander:timer_out
Nov 9, 2020
Merged

fix(log-rotate): avoid creating multiple timers#2596
spacewander merged 4 commits into
apache:masterfrom
spacewander:timer_out

Conversation

@spacewander

@spacewander spacewander commented Nov 2, 2020

Copy link
Copy Markdown
Member

What this PR does / why we need it:

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible?

@spacewander

Copy link
Copy Markdown
Member Author

This PR should be draft but I hit the wrong button by accident.

@spacewander spacewander changed the title fix(log-rotate): avoid creating multiple times WIP: fix(log-rotate): avoid creating multiple times Nov 2, 2020
@juzhiyuan
juzhiyuan marked this pull request as draft November 2, 2020 06:04
@spacewander spacewander changed the title WIP: fix(log-rotate): avoid creating multiple times fix(log-rotate): avoid creating multiple timers Nov 3, 2020
@spacewander
spacewander marked this pull request as ready for review November 3, 2020 08:25
Comment thread apisix/timers.lua Outdated
Comment thread t/plugin/log-rotate.t
Comment thread t/plugin/log-rotate.t
Comment thread apisix/timers.lua Outdated


function _M.init_worker()
-- currently only log-rotate needs the timer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

only for plugin log-rotate, the current way is enough.

but I think this library can be used for different plugins, it is basic library.

so I think we should remove https://github.com/apache/apisix/pull/2596/files#diff-6ff817ed7efbdfcf2da85cb1a68a48aa2ef9e18422b80b2f255fc41032ee773eR58-R60

@dabue dabue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've used the 'apisix/timers' in my local plug-in, it worked well.

Comment thread apisix/timers.lua Outdated
local timer, err = core.timer.new("background", background_timer, {check_interval = 0.5})
if not timer then
core.log.error("failed to create background timer: ", err)
else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we could return here,and remove 'else'

Comment thread apisix/timers.lua

local th, err = thread_spawn(timer)
if not th then
core.log.error("failed to spawn thread for timer [", name, "]: ", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we use 'continue' here,since it's empty?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@nic-chen
Updated.

@spacewander
spacewander merged commit d2d826e into apache:master Nov 9, 2020
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.

5 participants