Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time window functions as utility for auto-scaling #126

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -5674,20 +5674,20 @@ func SetNewWorkflow(resp http.ResponseWriter, request *http.Request) {
AppVersion: app.AppVersion,
AppID: app.ID,
LargeImage: app.LargeImage,
}
}

newAction.Position = Position{
X: 449.5,
Y: 446,
newAction.Position = Position{
X: 449.5,
Y: 446,
}

newActions = append(newActions, newAction)
}

newActions = append(newActions, newAction)
} else {
// figure out a way to activate Shuffle-Tools-Fork for everyone onprem
}

} else {
// figure out a way to activate Shuffle-Tools-Fork for everyone onprem
}

} else {
for _, item := range workflowapps {
//log.Printf("NAME: %s", item.Name)
Expand Down Expand Up @@ -17886,7 +17886,6 @@ func PrepareSingleAction(ctx context.Context, user User, fileId string, body []b
}
}


if runValidationAction {
log.Printf("[INFO] Running validation action for %s for org %s (%s)", app.Name, user.ActiveOrg.Name, user.ActiveOrg.Id)

Expand Down Expand Up @@ -29881,3 +29880,31 @@ func SendDeleteWorkflowRequest(childWorkflow Workflow, request *http.Request) er

return nil
}

func NewTimeWindow(duration time.Duration) *TimeWindow {
return &TimeWindow{
Duration: duration,
Events: []time.Time{},
}
}

func (tw *TimeWindow) AddEvent(event time.Time) {
tw.mu.Lock()
defer tw.mu.Unlock()
tw.Events = append(tw.Events, event)
tw.cleanOldEvents(event)
}

func (tw *TimeWindow) CountEvents(now time.Time) int {
tw.mu.Lock()
defer tw.mu.Unlock()
tw.cleanOldEvents(now)
return len(tw.Events)
}

func (tw *TimeWindow) cleanOldEvents(now time.Time) {
cutoff := now.Add(-tw.Duration)
for len(tw.Events) > 0 && tw.Events[0].Before(cutoff) {
tw.Events = tw.Events[1:]
}
}
17 changes: 12 additions & 5 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package shuffle

import (
"encoding/xml"
"sync"
"time"
)

Expand All @@ -24,7 +25,7 @@ type LogRequest struct {
}

type PipelineRequest struct {
ID string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Command string `json:"command"`
Expand All @@ -39,7 +40,7 @@ type PipelineRequest struct {

type Pipeline struct {
Name string `json:"name" datastore:"name"`
ID string `json:"id" datastore:"id"`
ID string `json:"id" datastore:"id"`
Type string `json:"type" datastore:"type"`
Command string `json:"command" datastore:"command"`
Environment string `json:"environment" datastore:"environment"`
Expand Down Expand Up @@ -1263,14 +1264,14 @@ type InputQuestion struct {
}

type FormControl struct {
InputMarkdown string `json:"input_markdown" datastore:"input_markdown,noindex"`
OutputYields []string `json:"output_yields" datastore:"output_yields"` // Defines the nodes that will YIELD their output to the frontend during execution
InputMarkdown string `json:"input_markdown" datastore:"input_markdown,noindex"`
OutputYields []string `json:"output_yields" datastore:"output_yields"` // Defines the nodes that will YIELD their output to the frontend during execution

FormWidth int64 `json:"form_width" datastore:"form_width"`
}

type Workflow struct {
WorkflowAsCode bool `json:"workflow_as_code" datastore:"workflow_as_code"`
WorkflowAsCode bool `json:"workflow_as_code" datastore:"workflow_as_code"`
Actions []Action `json:"actions" datastore:"actions,noindex"`
Branches []Branch `json:"branches" datastore:"branches,noindex"`
VisualBranches []Branch `json:"visual_branches" datastore:"visual_branches,noindex"`
Expand Down Expand Up @@ -4169,3 +4170,9 @@ type RequestResponse struct {
Reason string `json:"reason"`
Details string `json:"details"`
}

type TimeWindow struct {
Duration time.Duration
Events []time.Time
mu sync.Mutex
}
Loading