You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
619 B
27 lines
619 B
package simulation |
|
|
|
// keep this stateless. Trying to store state here is a big mistake. |
|
// This is meant to be a pure logic handler. |
|
type WebServerLogic struct { |
|
} |
|
|
|
func (l WebServerLogic) Tick(props map[string]any, queue []*Request, tick int) ([]*Request, bool) { |
|
maxRPS := int(AsFloat64(props["rpsCapacity"])) |
|
|
|
toProcess := queue |
|
if len(queue) > maxRPS { |
|
toProcess = queue[:maxRPS] |
|
} |
|
|
|
var output []*Request |
|
for _, req := range toProcess { |
|
output = append(output, &Request{ |
|
ID: req.ID, |
|
Timestamp: req.Timestamp, |
|
Origin: req.Origin, |
|
Type: req.Type, |
|
}) |
|
} |
|
|
|
return output, true |
|
}
|
|
|