Skip to content

Commit

Permalink
Merge pull request #126 from yashsinghcodes/autoscale
Browse files Browse the repository at this point in the history
Time window functions as utility for auto-scaling
  • Loading branch information
frikky authored Nov 30, 2024
2 parents ad4e222 + 23134fd commit 21fcb39
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
46 changes: 37 additions & 9 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 @@ -29859,3 +29859,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
}

0 comments on commit 21fcb39

Please sign in to comment.