Skip to content

Commit 59497ba

Browse files
committed
add worker disable flag
1 parent cf81754 commit 59497ba

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ This project is a standalone worker that continuosly:
77

88
### Command line flags
99
```
10-
wkr-gh-sponsor🐚 ➜ wkr-gh-sponsor git:(master) ./scripts/wkr-gh-sponsor --help
11-
Usage: wkr-gh-sponsor --db-path="db.sql" --td-api-key=TD-API-KEY --gh-classic-access-token=GH-ACCESS-TOKEN --entities=ENTITIES,...
10+
➜ wkr-gh-sponsor git:(master) ./scripts/wkr-gh-sponsor --help
11+
Usage: wkr-gh-sponsor --db-path="db.sql" --td-api-url="https://api.thanks.dev/v1/deps" --td-api-key=TD-API-KEY --gh-classic-access-token=GH-ACCESS-TOKEN --entities=ENTITIES,...
1212
1313
Flags:
1414
-h, --help Show context-sensitive help.
1515
-v, --version Print version and exit.
1616
-C, --config=FILE Config file ($CONFIG_PATH).
17-
-e, --env=local Environment (local,prod) ($APP_ENV).
18-
--db-path="db.sql" Path to db file.
19-
--td-api-key=TD-API-KEY Api key for thanks.dev ($TD_API_KEY).
17+
--db-path="db.sql" Path to db file ($DB_PATH).
18+
--td-api-url="https://api.thanks.dev/v1/deps"
19+
thanks.dev API URL ($TD_API_URL).
20+
--td-api-key=TD-API-KEY thanks.dev API key ($TD_API_KEY).
2021
--gh-classic-access-token=GH-ACCESS-TOKEN
2122
GitHub classis access token with admin:org & user scopes ($GH_CLASSIC_ACCESS_TOKEN).
2223
--entities=ENTITIES,... The GitHub entities to process sponsorships for. First entity in the list is
2324
considered DEFAULT.
25+
--wkr-td-disabled Disable worker.
26+
--wkr-animate-disabled Disable worker.
27+
--wkr-donate-disabled Disable worker.
2428
2529
Observability:
2630
--log-level=info Log level (trace,debug,info,warning,error,fatal,panic).

cmd/wkr-gh-sponsor/main.go

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ import (
2626
// Populated during build.
2727
var GitCommit string = "dev"
2828

29+
type wkr_config struct {
30+
Disabled bool `help:"Disable worker." default:"false"`
31+
}
32+
2933
var cli struct {
3034
Version kong.VersionFlag `short:"v" help:"Print version and exit."`
3135
Config kong.ConfigFlag `short:"C" help:"Config file." placeholder:"FILE" env:"CONFIG_PATH"`
@@ -39,6 +43,10 @@ var cli struct {
3943
GhClassicAccessToken wkrghsponsor.GhAccessToken `help:"GitHub classis access token with admin:org & user scopes." required:"" env:"GH_CLASSIC_ACCESS_TOKEN"`
4044

4145
Entities []wkrghsponsor.Entity `help:"The GitHub entities to process sponsorships for. First entity in the list is considered DEFAULT." required:""`
46+
47+
WkrTd wkr_config `embed:"" prefix:"wkr-td-"`
48+
WkrAnimate wkr_config `embed:"" prefix:"wkr-animate-"`
49+
WkrDonate wkr_config `embed:"" prefix:"wkr-donate-"`
4250
}
4351

4452
func main() {
@@ -103,21 +111,25 @@ func main() {
103111
wkrs := []struct {
104112
name string
105113
fn any
114+
disabled bool
106115
workInterval time.Duration
107116
}{
108117
{
109118
name: "wkr-td",
110119
fn: wkrtd.New,
120+
disabled: cli.WkrTd.Disabled,
111121
workInterval: time.Hour * 3, // 4 times a day
112122
},
113123
{
114124
name: "wkr-animate",
115125
fn: wkranimate.New,
126+
disabled: cli.WkrAnimate.Disabled,
116127
workInterval: time.Minute, // once a minute
117128
},
118129
{
119130
name: "wkr-donate",
120131
fn: wkrdonate.New,
132+
disabled: cli.WkrDonate.Disabled,
121133
workInterval: time.Minute, // once a minute
122134
},
123135
}
@@ -127,6 +139,11 @@ func main() {
127139
logger := logger.WithField("name", w.name)
128140
ctx := log.LoggerContext(ctx, logger)
129141

142+
if w.disabled {
143+
logger.Infof("Worker %s not enabled", w.name)
144+
continue
145+
}
146+
130147
out, err := kctx.Call(w.fn)
131148
if err != nil {
132149
logger.WithError(err).Error("failed to start")

0 commit comments

Comments
 (0)