Skip to content

Commit

Permalink
fix: Update Example Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
sirateek committed Mar 25, 2024
1 parent 6d940af commit 1ec151a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,36 @@ import (
"time"
)

type TaskAttribute struct {
SleepTime *time.Duration `json:"sleepTime,omitempty"`
MemoryAllocationSize *int `json:"memoryAllocationSize,omitempty"`
}

func main() {
containerlib.Run(func(ctx containerlibcontext.Context, task model.Task) error {
var unmarshalledData map[string]interface{}
var unmarshalledData TaskAttribute
err := json.Unmarshal(task.Attributes, &unmarshalledData)
if err != nil {
logrus.Error(err)
return err
}

time.Sleep(15 * time.Second)
if unmarshalledData.SleepTime == nil {
sleepTime := 15 * time.Second
unmarshalledData.SleepTime = &sleepTime
}

if unmarshalledData.MemoryAllocationSize == nil {
size := 0
unmarshalledData.MemoryAllocationSize = &size
}

fakeAllocation := make([]byte, *unmarshalledData.MemoryAllocationSize)
for i := 0; i < *unmarshalledData.MemoryAllocationSize; i++ {
fakeAllocation[i] = 0x99
}

time.Sleep(*unmarshalledData.SleepTime)
fmt.Println(unmarshalledData)

ctx.Success()
Expand Down

0 comments on commit 1ec151a

Please sign in to comment.