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

feat(worker): support graceful shutdown #459

Merged
merged 4 commits into from
Feb 4, 2020
Merged

feat(worker): support graceful shutdown #459

merged 4 commits into from
Feb 4, 2020

Conversation

appleboy
Copy link
Owner

@appleboy appleboy commented Feb 4, 2020

notifications workers and queue have are sent to APNs/FCM before a push notification service is shutdown.

fixed: #441

how to test

# build docker
make build_linux_amd64 docker_image 

create a new console:

$ docker-compose up
Creating network "gorush_default" with the default driver
Creating gorush_gorush_1 ... done
Attaching to gorush_gorush_1
gorush_1  | time="2020/02/04 - 03:43:07" level=info msg="Init App Status Engine as memory"
gorush_1  | time="2020/02/04 - 03:43:07" level=info msg="worker number is 2, queue number is 512"
gorush_1  | time="2020/02/04 - 03:43:07" level=info msg="gRPC server is disabled."
gorush_1  | time="2020/02/04 - 03:43:07" level=info msg="HTTPD server is running on 8088 port."

create another console:

$ docker-compose down

You will see the log in the first console:

gorush_1  | time="2020/02/04 - 03:43:48" level=info msg="| header | GET /healthz 127.0.0.1  Go-http-client/1.1"
gorush_1  | [GIN] 2020/02/04 - 03:43:48 | 200 |     112.987µs |       127.0.0.1 | GET      /healthz
gorush_1  | time="2020/02/04 - 03:43:56" level=info msg="close the notification queue channel"
gorush_1  | time="2020/02/04 - 03:43:56" level=info msg="closed the worker num 1"
gorush_1  | time="2020/02/04 - 03:43:56" level=info msg="closed the worker num 0"
gorush_1  | time="2020/02/04 - 03:43:56" level=info msg="the notification queue has been clear"
gorush_1  | time="2020/02/04 - 03:43:58" level=info msg="| header | GET /healthz 127.0.0.1  Go-http-client/1.1"
gorush_1  | [GIN] 2020/02/04 - 03:43:58 | 200 |     102.607µs |       127.0.0.1 | GET      /healthz

Signed-off-by: Bo-Yi Wu [email protected]

notifications workers and queue have are sent to APNs/FCM before a push notification service is shutdown.

fixed: #441

Signed-off-by: Bo-Yi Wu <[email protected]>
ctx, cancel := context.WithCancel(ctx)
go func() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)

Choose a reason for hiding this comment

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

SA1017: the channel used with signal.Notify should be buffered (from staticcheck)

Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
send buffered channel to signal.Notify to avoid blocking

golang/lint#175

Signed-off-by: Bo-Yi Wu <[email protected]>
main.go Outdated
ctx, cancel := context.WithCancel(ctx)
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)

Choose a reason for hiding this comment

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

SA1016: os.Kill cannot be trapped (did you mean syscall.SIGTERM?) (from staticcheck)

@codecov-io
Copy link

codecov-io commented Feb 4, 2020

Codecov Report

Merging #459 into master will decrease coverage by 0.05%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #459      +/-   ##
==========================================
- Coverage   83.05%   82.99%   -0.06%     
==========================================
  Files          20       20              
  Lines        1393     1394       +1     
==========================================
  Hits         1157     1157              
- Misses        188      189       +1     
  Partials       48       48
Impacted Files Coverage Δ
rpc/server.go 0% <0%> (ø) ⬆️
gorush/status.go 85% <100%> (ø) ⬆️
gorush/server_normal.go 78.04% <100%> (ø) ⬆️
gorush/worker.go 85.48% <85.71%> (-1.41%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bcf1c0c...d2e560a. Read the comment docs.

@appleboy appleboy merged commit 2d2a8a0 into master Feb 4, 2020
@appleboy appleboy deleted the graceful branch February 4, 2020 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does the gorush support graceful shutdown?
3 participants