Skip to content

Commit

Permalink
add worker disable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nehzata committed Sep 20, 2023
1 parent cf81754 commit 59497ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ This project is a standalone worker that continuosly:

### Command line flags
```
wkr-gh-sponsor🐚 ➜ wkr-gh-sponsor git:(master) ./scripts/wkr-gh-sponsor --help
Usage: wkr-gh-sponsor --db-path="db.sql" --td-api-key=TD-API-KEY --gh-classic-access-token=GH-ACCESS-TOKEN --entities=ENTITIES,...
➜ wkr-gh-sponsor git:(master) ./scripts/wkr-gh-sponsor --help
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,...
Flags:
-h, --help Show context-sensitive help.
-v, --version Print version and exit.
-C, --config=FILE Config file ($CONFIG_PATH).
-e, --env=local Environment (local,prod) ($APP_ENV).
--db-path="db.sql" Path to db file.
--td-api-key=TD-API-KEY Api key for thanks.dev ($TD_API_KEY).
--db-path="db.sql" Path to db file ($DB_PATH).
--td-api-url="https://api.thanks.dev/v1/deps"
thanks.dev API URL ($TD_API_URL).
--td-api-key=TD-API-KEY thanks.dev API key ($TD_API_KEY).
--gh-classic-access-token=GH-ACCESS-TOKEN
GitHub classis access token with admin:org & user scopes ($GH_CLASSIC_ACCESS_TOKEN).
--entities=ENTITIES,... The GitHub entities to process sponsorships for. First entity in the list is
considered DEFAULT.
--wkr-td-disabled Disable worker.
--wkr-animate-disabled Disable worker.
--wkr-donate-disabled Disable worker.
Observability:
--log-level=info Log level (trace,debug,info,warning,error,fatal,panic).
Expand Down
17 changes: 17 additions & 0 deletions cmd/wkr-gh-sponsor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
// Populated during build.
var GitCommit string = "dev"

type wkr_config struct {
Disabled bool `help:"Disable worker." default:"false"`
}

var cli struct {
Version kong.VersionFlag `short:"v" help:"Print version and exit."`
Config kong.ConfigFlag `short:"C" help:"Config file." placeholder:"FILE" env:"CONFIG_PATH"`
Expand All @@ -39,6 +43,10 @@ var cli struct {
GhClassicAccessToken wkrghsponsor.GhAccessToken `help:"GitHub classis access token with admin:org & user scopes." required:"" env:"GH_CLASSIC_ACCESS_TOKEN"`

Entities []wkrghsponsor.Entity `help:"The GitHub entities to process sponsorships for. First entity in the list is considered DEFAULT." required:""`

WkrTd wkr_config `embed:"" prefix:"wkr-td-"`
WkrAnimate wkr_config `embed:"" prefix:"wkr-animate-"`
WkrDonate wkr_config `embed:"" prefix:"wkr-donate-"`
}

func main() {
Expand Down Expand Up @@ -103,21 +111,25 @@ func main() {
wkrs := []struct {
name string
fn any
disabled bool
workInterval time.Duration
}{
{
name: "wkr-td",
fn: wkrtd.New,
disabled: cli.WkrTd.Disabled,
workInterval: time.Hour * 3, // 4 times a day
},
{
name: "wkr-animate",
fn: wkranimate.New,
disabled: cli.WkrAnimate.Disabled,
workInterval: time.Minute, // once a minute
},
{
name: "wkr-donate",
fn: wkrdonate.New,
disabled: cli.WkrDonate.Disabled,
workInterval: time.Minute, // once a minute
},
}
Expand All @@ -127,6 +139,11 @@ func main() {
logger := logger.WithField("name", w.name)
ctx := log.LoggerContext(ctx, logger)

if w.disabled {
logger.Infof("Worker %s not enabled", w.name)
continue
}

out, err := kctx.Call(w.fn)
if err != nil {
logger.WithError(err).Error("failed to start")
Expand Down

0 comments on commit 59497ba

Please sign in to comment.