Skip to content

Commit 0569858

Browse files
committed
support signal handling
1 parent 0ef6867 commit 0569858

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

check-aws-sqs-queue-size/lib/check-aws-sqs-queue-size.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"os/signal"
89
"strconv"
910

1011
"github.com/aws/aws-sdk-go-v2/aws"
@@ -16,9 +17,15 @@ import (
1617
"github.com/mackerelio/checkers"
1718
)
1819

20+
// overwritten with syscall.SIGTERM on unix environment (see check-log_unix.go)
21+
var defaultSignal = os.Interrupt
22+
1923
// Do the plugin
2024
func Do() {
21-
ckr := run(os.Args[1:])
25+
ctx, stop := signal.NotifyContext(context.Background(), defaultSignal)
26+
defer stop()
27+
28+
ckr := run(ctx, os.Args[1:])
2229
ckr.Name = "SQSQueueSize"
2330
ckr.Exit()
2431
}
@@ -89,9 +96,7 @@ func getSqsQueueSize(ctx context.Context, region, awsAccessKeyID, awsSecretAcces
8996
return size, nil
9097
}
9198

92-
func run(args []string) *checkers.Checker {
93-
ctx := context.Background()
94-
99+
func run(ctx context.Context, args []string) *checkers.Checker {
95100
_, err := flags.ParseArgs(&opts, args)
96101
if err != nil {
97102
os.Exit(1)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package checkawssqsqueuesize
2+
3+
import (
4+
"syscall"
5+
)
6+
7+
func init() {
8+
defaultSignal = syscall.SIGTERM
9+
}

0 commit comments

Comments
 (0)