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

feature(core): implement core.sleep #2170

Closed
membphis opened this issue Sep 4, 2020 · 3 comments · Fixed by #2397
Closed

feature(core): implement core.sleep #2170

membphis opened this issue Sep 4, 2020 · 3 comments · Fixed by #2397

Comments

@membphis
Copy link
Member

membphis commented Sep 4, 2020

Use a small time interval (such as 1s) to complete a relatively long sleep behavior, so that the worker process can be shut down gracefully.

Here is the fake code(we may):

function sleep(sec)
    if sec <= 1 then
        ngx_sleep(sec)
        return
    end

    while true do
        if sec > 1 then
            ngx_sleep(1)
        end

        if exiting() then
            return
        end

        sec = sec - 1
        if sec < 1 then
            ngx_sleep(sec)
            return
        end
    end
end
@dabue
Copy link
Contributor

dabue commented Oct 12, 2020

please assign it to me.

@dabue
Copy link
Contributor

dabue commented Oct 12, 2020

I 'll add a new function sleep to the file apisix/core.lua, and replace all filed ‘sleep = ngx.sleep’ with 'sleep = require("apisix.core.sleep")'. Is that OK?

@membphis
Copy link
Member Author

it is fine, let us do it ^_^

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 a pull request may close this issue.

2 participants