-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HARMONY-1974: Implement work reaper and work failer (started) in go
- Loading branch information
1 parent
9ce2b1e
commit 83dc63d
Showing
8 changed files
with
165 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
core-services/internal/cronjobs/workfailer/env-defaults.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package workfailer | ||
|
||
// The cron entry for scheduling the work reaper | ||
const WORK_FAILER_CRON = "@every 300s" | ||
|
||
// WorkItems that have not been updated for more than this many minutes are | ||
// updated by the work failer (resulting either in job and work item failure or a retry) | ||
const FAILABLE_WORK_AGE_MINUTES = 5 | ||
|
||
// The batch size used by work-failer. Set it to 0 will effectively disable work-failer. | ||
const WORK_FAILER_BATCH_SIZE = 1000 | ||
|
||
// Maximum number of work items allowed on the work item update queue before halting failing work items | ||
// Set the value to -1 to always fail work items | ||
const MAX_WORK_ITEMS_ON_UPDATE_QUEUE_FAILER = 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Environment variables for the work failer | ||
package workfailer | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/go-playground/validator/v10" | ||
"github.com/nasa/harmony/core-services/internal/env" | ||
) | ||
|
||
type WorkFailerEnv struct { | ||
env.HarmonyEnv | ||
WorkFailerCron string `validate:"required,cron"` | ||
WorkFailerBatchSize int `validate:"gte=1"` | ||
FailableWorkAgeMinutes int `validate:"gte=1"` | ||
MaxWorkItemsOnUpdateQueueFailer int `validate:"gte1"` | ||
} | ||
|
||
func InitEnv(baseEnv env.HarmonyEnv) WorkFailerEnv { | ||
cronEntry := os.Getenv("WORK_FAILER_CRON") | ||
if cronEntry == "" { | ||
cronEntry = WORK_FAILER_CRON | ||
} | ||
|
||
batchSize, err := strconv.Atoi(os.Getenv("WORK_FAILER_BATCH_SIZE")) | ||
if err != nil { | ||
batchSize = WORK_FAILER_BATCH_SIZE | ||
} | ||
failableWorkAgeMinutes, err := strconv.Atoi(os.Getenv("FAILABLE_WORK_AGE_MINUTES")) | ||
if err != nil { | ||
failableWorkAgeMinutes = FAILABLE_WORK_AGE_MINUTES | ||
} | ||
maxWorkItemsOnUpdateQueueFailer, err := strconv.Atoi(os.Getenv("MAX_WORK_ITEMS_ON_UPDATE_QUEUE_FAILER")) | ||
if err != nil { | ||
maxWorkItemsOnUpdateQueueFailer = MAX_WORK_ITEMS_ON_UPDATE_QUEUE_FAILER | ||
} | ||
|
||
env := WorkFailerEnv{ | ||
baseEnv, | ||
cronEntry, | ||
batchSize, | ||
failableWorkAgeMinutes, | ||
maxWorkItemsOnUpdateQueueFailer, | ||
} | ||
|
||
validate := validator.New(validator.WithRequiredStructEnabled()) | ||
err = validate.Struct(env) | ||
if err != nil { | ||
fmt.Println("Invalid work failer env vars") | ||
panic(err) | ||
} | ||
|
||
return env | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package workfailer | ||
|
||
// import ( | ||
// "context" | ||
// _ "fmt" | ||
// _ "os" | ||
// _ "strconv" | ||
|
||
// "github.com/nasa/harmony/core-services/internal/db" | ||
// logs "github.com/nasa/harmony/core-services/internal/log" | ||
// "github.com/nasa/harmony/core-services/internal/models/job" | ||
// ) | ||
|
||
// func getExpiredWorkItems(ctx context.Context) { | ||
|
||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package workreaper | ||
|
||
// The cron entry for scheduling the work reaper | ||
const WORK_REAPER_CRON = "@every 30s" | ||
|
||
// WorkItems and WorkflowSteps (in a terminal state) older than this many minutes are checked by the work reaper | ||
const REAPABLE_WORK_AGE_MINUTES = 20160 | ||
|
||
// The batch size of the work reaper service | ||
const WORK_REAPER_BATCH_SIZE = 2000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Environment variables for the work reaper | ||
package workreaper | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/go-playground/validator/v10" | ||
"github.com/nasa/harmony/core-services/internal/env" | ||
) | ||
|
||
type WorkReaperEnv struct { | ||
env.HarmonyEnv | ||
WorkReaperCron string `validate:"required,cron"` | ||
WorkReaperBatchSize int `validate:"gte=1"` | ||
ReapableWorkAgeMinutes int `validate:"gte=1"` | ||
} | ||
|
||
func InitEnv(baseEnv env.HarmonyEnv) WorkReaperEnv { | ||
cronEntry := os.Getenv("WORK_REAPER_CRON") | ||
if cronEntry == "" { | ||
cronEntry = WORK_REAPER_CRON | ||
} | ||
|
||
batchSize, err := strconv.Atoi(os.Getenv("WORK_REAPER_BATCH_SIZE")) | ||
if err != nil { | ||
batchSize = WORK_REAPER_BATCH_SIZE | ||
} | ||
reapableWorkAgeMinutes, err := strconv.Atoi(os.Getenv("REAPABLE_WORK_AGE_MINUTES")) | ||
if err != nil { | ||
reapableWorkAgeMinutes = REAPABLE_WORK_AGE_MINUTES | ||
} | ||
|
||
env := WorkReaperEnv{ | ||
baseEnv, | ||
cronEntry, | ||
batchSize, | ||
reapableWorkAgeMinutes, | ||
} | ||
|
||
validate := validator.New(validator.WithRequiredStructEnabled()) | ||
err = validate.Struct(env) | ||
if err != nil { | ||
fmt.Println("Invalid work reaper env vars") | ||
panic(err) | ||
} | ||
|
||
return env | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters