Skip to content

Commit 21fcb39

Browse files
authored
Merge pull request #126 from yashsinghcodes/autoscale
Time window functions as utility for auto-scaling
2 parents ad4e222 + 23134fd commit 21fcb39

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

shared.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5674,20 +5674,20 @@ func SetNewWorkflow(resp http.ResponseWriter, request *http.Request) {
56745674
AppVersion: app.AppVersion,
56755675
AppID: app.ID,
56765676
LargeImage: app.LargeImage,
5677-
}
5677+
}
56785678

5679-
newAction.Position = Position{
5680-
X: 449.5,
5681-
Y: 446,
5679+
newAction.Position = Position{
5680+
X: 449.5,
5681+
Y: 446,
5682+
}
5683+
5684+
newActions = append(newActions, newAction)
56825685
}
56835686

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

5687-
} else {
5688-
// figure out a way to activate Shuffle-Tools-Fork for everyone onprem
5689-
}
5690-
56915691
} else {
56925692
for _, item := range workflowapps {
56935693
//log.Printf("NAME: %s", item.Name)
@@ -29859,3 +29859,31 @@ func SendDeleteWorkflowRequest(childWorkflow Workflow, request *http.Request) er
2985929859

2986029860
return nil
2986129861
}
29862+
29863+
func NewTimeWindow(duration time.Duration) *TimeWindow {
29864+
return &TimeWindow{
29865+
Duration: duration,
29866+
Events: []time.Time{},
29867+
}
29868+
}
29869+
29870+
func (tw *TimeWindow) AddEvent(event time.Time) {
29871+
tw.mu.Lock()
29872+
defer tw.mu.Unlock()
29873+
tw.Events = append(tw.Events, event)
29874+
tw.cleanOldEvents(event)
29875+
}
29876+
29877+
func (tw *TimeWindow) CountEvents(now time.Time) int {
29878+
tw.mu.Lock()
29879+
defer tw.mu.Unlock()
29880+
tw.cleanOldEvents(now)
29881+
return len(tw.Events)
29882+
}
29883+
29884+
func (tw *TimeWindow) cleanOldEvents(now time.Time) {
29885+
cutoff := now.Add(-tw.Duration)
29886+
for len(tw.Events) > 0 && tw.Events[0].Before(cutoff) {
29887+
tw.Events = tw.Events[1:]
29888+
}
29889+
}

structs.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shuffle
22

33
import (
44
"encoding/xml"
5+
"sync"
56
"time"
67
)
78

@@ -24,7 +25,7 @@ type LogRequest struct {
2425
}
2526

2627
type PipelineRequest struct {
27-
ID string `json:"id"`
28+
ID string `json:"id"`
2829
Name string `json:"name"`
2930
Type string `json:"type"`
3031
Command string `json:"command"`
@@ -39,7 +40,7 @@ type PipelineRequest struct {
3940

4041
type Pipeline struct {
4142
Name string `json:"name" datastore:"name"`
42-
ID string `json:"id" datastore:"id"`
43+
ID string `json:"id" datastore:"id"`
4344
Type string `json:"type" datastore:"type"`
4445
Command string `json:"command" datastore:"command"`
4546
Environment string `json:"environment" datastore:"environment"`
@@ -1263,14 +1264,14 @@ type InputQuestion struct {
12631264
}
12641265

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

12691270
FormWidth int64 `json:"form_width" datastore:"form_width"`
12701271
}
12711272

12721273
type Workflow struct {
1273-
WorkflowAsCode bool `json:"workflow_as_code" datastore:"workflow_as_code"`
1274+
WorkflowAsCode bool `json:"workflow_as_code" datastore:"workflow_as_code"`
12741275
Actions []Action `json:"actions" datastore:"actions,noindex"`
12751276
Branches []Branch `json:"branches" datastore:"branches,noindex"`
12761277
VisualBranches []Branch `json:"visual_branches" datastore:"visual_branches,noindex"`
@@ -4169,3 +4170,9 @@ type RequestResponse struct {
41694170
Reason string `json:"reason"`
41704171
Details string `json:"details"`
41714172
}
4173+
4174+
type TimeWindow struct {
4175+
Duration time.Duration
4176+
Events []time.Time
4177+
mu sync.Mutex
4178+
}

0 commit comments

Comments
 (0)