Many minor fixes
This commit is contained in:
@@ -4,7 +4,9 @@ go 1.24.0
|
||||
|
||||
toolchain go1.24.3
|
||||
|
||||
//replace github.com/shuffle/opensearch-go => ../../../opensearch-go
|
||||
//replace github.com/shuffle/shuffle-shared => ../../../shuffle-shared
|
||||
|
||||
//replace github.com/frikky/schemaless => ../../../schemaless
|
||||
|
||||
//replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi
|
||||
@@ -24,7 +26,7 @@ require (
|
||||
github.com/gorilla/mux v1.8.1
|
||||
github.com/h2non/filetype v1.1.3
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/shuffle/shuffle-shared v0.9.32
|
||||
github.com/shuffle/shuffle-shared v0.9.33
|
||||
github.com/shuffle/singul v0.0.17
|
||||
golang.org/x/crypto v0.40.0
|
||||
google.golang.org/api v0.236.0
|
||||
|
||||
@@ -363,8 +363,8 @@ github.com/sendgrid/sendgrid-go v3.16.1+incompatible h1:zWhTmB0Y8XCDzeWIm2/BIt1G
|
||||
github.com/sendgrid/sendgrid-go v3.16.1+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
|
||||
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
|
||||
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
|
||||
github.com/shuffle/shuffle-shared v0.9.32 h1:hsF2YkKHgaNpqhh2oZs31BgPSjN+YjGNnd9WmD0qh3w=
|
||||
github.com/shuffle/shuffle-shared v0.9.32/go.mod h1:vfI2QDGphZGrcwuUPQ1yI/Hgc8aseFro5+2k36irfkQ=
|
||||
github.com/shuffle/shuffle-shared v0.9.33 h1:Fig5lJhRAmBtwI8C8KIf2OGNAWJAtdi/2XtK1qg1U/o=
|
||||
github.com/shuffle/shuffle-shared v0.9.33/go.mod h1:WbLPLyBrh86ieRBgDyjC43M2qBF8a7E8jO8Pv7t8SOk=
|
||||
github.com/shuffle/singul v0.0.17 h1:mxaPtj6z85Nf6tl7L2gwDliTfEZtRQqApuu9iKcP75o=
|
||||
github.com/shuffle/singul v0.0.17/go.mod h1:8c42n1NahhCIPxzLxwp9eYbWkvY4+ct0jfbhkRsRRsY=
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
|
||||
+3
-101
@@ -249,7 +249,7 @@ func handleGetWorkflowqueueConfirm(resp http.ResponseWriter, request *http.Reque
|
||||
resp.Write([]byte(`{"success": true}`))
|
||||
}
|
||||
|
||||
// FIXME: Authenticate this one? Can org ID be auth enough?
|
||||
// FIXME: Authenticate this one. Can org ID be auth enough?
|
||||
// (especially since we have a default: shuffle)
|
||||
func handleGetWorkflowqueue(resp http.ResponseWriter, request *http.Request) {
|
||||
cors := shuffle.HandleCors(resp, request)
|
||||
@@ -325,7 +325,7 @@ func handleGetWorkflowqueue(resp http.ResponseWriter, request *http.Request) {
|
||||
orgId = env.OrgId
|
||||
}
|
||||
|
||||
executionRequests, err := shuffle.GetWorkflowQueue(ctx, environment, 100)
|
||||
executionRequests, err := shuffle.GetWorkflowQueue(ctx, environment, 100, *env)
|
||||
if err != nil {
|
||||
resp.WriteHeader(500)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
|
||||
@@ -336,106 +336,8 @@ func handleGetWorkflowqueue(resp http.ResponseWriter, request *http.Request) {
|
||||
if len(executionRequests.Data) == 0 {
|
||||
executionRequests.Data = []shuffle.ExecutionRequest{}
|
||||
} else {
|
||||
|
||||
// Try again? I don't think this is necessary, and shouldn't really ever occur.
|
||||
/*
|
||||
if len(env.Id) == 0 && len(env.Name) == 0 {
|
||||
timeNow := int64(time.Now().Unix())
|
||||
foundId := ""
|
||||
for _, requestData := range executionRequests.Data {
|
||||
execution, err := shuffle.GetWorkflowExecution(ctx, requestData.ExecutionId)
|
||||
if err == nil {
|
||||
if len(execution.ExecutionOrg) > 0 {
|
||||
foundId = execution.ExecutionOrg
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(environment) > 0 {
|
||||
|
||||
env, err := shuffle.GetEnvironment(ctx, environment, foundId)
|
||||
if err != nil {
|
||||
log.Printf("[WARNING] No env found matching %s - continuing without updating orborus anyway: %s", environment, err)
|
||||
//resp.WriteHeader(401)
|
||||
//resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "No env found matching %s"}`, id)))
|
||||
//return
|
||||
} else {
|
||||
if timeNow > env.Edited+60 {
|
||||
env.RunningIp = request.RemoteAddr
|
||||
env.Checkin = timeNow
|
||||
err = shuffle.SetEnvironment(ctx, env)
|
||||
if err != nil {
|
||||
log.Printf("[WARNING] Failed updating environment: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
orgId := env.OrgId
|
||||
org, err := shuffle.GetOrg(ctx, orgId)
|
||||
if err != nil {
|
||||
log.Printf("[WARNING] Failed getting org %s for queue: %s", orgId, err)
|
||||
}
|
||||
|
||||
parentOrg := org
|
||||
if len(org.CreatorOrg) > 0 {
|
||||
parentOrg, err = shuffle.GetOrg(ctx, org.CreatorOrg)
|
||||
if err != nil {
|
||||
log.Printf("[WARNING] Failed getting parent org %s for queue: %s", org.CreatorOrg, err)
|
||||
}
|
||||
}
|
||||
|
||||
licenseOrg := shuffle.HandleCheckLicense(ctx, *parentOrg)
|
||||
stats, err := shuffle.GetOrgStatistics(ctx, parentOrg.Id)
|
||||
if err != nil {
|
||||
log.Printf("[WARNING] Failed getting statistics for org %s: %s", parentOrg.Id, err)
|
||||
}
|
||||
|
||||
limit := licenseOrg.SyncFeatures.WorkflowExecutions.Limit
|
||||
totalWorkflowExecutions := stats.MonthlyWorkflowExecutions + stats.MonthlyChildWorkflowExecutions
|
||||
if totalWorkflowExecutions > limit {
|
||||
|
||||
cacheKey := fmt.Sprintf("org-%s-last-queue-send", orgId)
|
||||
currentTime := time.Now().Unix()
|
||||
lastSendCache, err := shuffle.GetCache(ctx, cacheKey)
|
||||
if err == nil {
|
||||
var lastSendTime int64
|
||||
if timeBytes, ok := lastSendCache.([]byte); ok {
|
||||
if unmarshallErr := json.Unmarshal(timeBytes, &lastSendTime); unmarshallErr == nil {
|
||||
timeSinceLastSend := currentTime - lastSendTime
|
||||
|
||||
if timeSinceLastSend < 60 {
|
||||
log.Printf("[INFO] Rate limiting: Org %s exceeded the 10K usage quota for non-licensed users (current queued: %d, current month usage: %d). To increase scale, upgrade to an Enterprise license.", orgId, len(executionRequests.Data), totalWorkflowExecutions)
|
||||
executionRequests.Data = []shuffle.ExecutionRequest{}
|
||||
} else {
|
||||
if len(executionRequests.Data) > 1 {
|
||||
log.Printf("[INFO] Rate limiting: Org %s exceeded the 10K usage quota for non-licensed users (current queued: %d, current month usage: %d). To increase scale, upgrade to an Enterprise license.", orgId, len(executionRequests.Data), totalWorkflowExecutions)
|
||||
executionRequests.Data = executionRequests.Data[0:1]
|
||||
}
|
||||
|
||||
timeBytes, _ := json.Marshal(currentTime)
|
||||
if cacheErr := shuffle.SetCache(ctx, cacheKey, timeBytes, 1); cacheErr != nil {
|
||||
log.Printf("[WARNING] Failed to set rate limiting cache for org %s: %s", orgId, cacheErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if len(executionRequests.Data) > 1 {
|
||||
log.Printf("[INFO] Rate limiting: Org %s exceeded the 10K usage quota for non-licensed users (current queued: %d, current month usage: %d). To increase scale, upgrade to an Enterprise license.", orgId, len(executionRequests.Data), totalWorkflowExecutions)
|
||||
executionRequests.Data = executionRequests.Data[0:1]
|
||||
}
|
||||
|
||||
timeBytes, _ := json.Marshal(currentTime)
|
||||
if cacheErr := shuffle.SetCache(ctx, cacheKey, timeBytes, 1); cacheErr != nil {
|
||||
log.Printf("[WARNING] Failed to set initial rate limiting cache for org %s: %s", orgId, cacheErr)
|
||||
}
|
||||
}
|
||||
} else if len(executionRequests.Data) > 50 {
|
||||
if len(executionRequests.Data) > 50 {
|
||||
executionRequests.Data = executionRequests.Data[0:49]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user