Skip to content

Commit

Permalink
make sleep time configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Julie Vogelman <[email protected]>
  • Loading branch information
juliev0 committed Jan 16, 2025
1 parent ae96c3d commit dd1b8c4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/mapper/examples/cat_sleep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@ package main
import (
"context"
"log"
"os"
"strconv"
"time"

"github.com/numaproj/numaflow-go/pkg/mapper"
)

const DEFAULT_SLEEP_SECONDS = 10

type CatSleep struct {
}

func (e *CatSleep) Map(ctx context.Context, keys []string, d mapper.Datum) mapper.Messages {
time.Sleep(10 * time.Second)

sleepSeconds := DEFAULT_SLEEP_SECONDS
secondsString := os.Getenv("SLEEP_SECONDS")
if secondsString == "" {
log.Printf("SLEEP_SECONDS environment variable not set, using default %d seconds\n", DEFAULT_SLEEP_SECONDS)
} else {
val, err := strconv.Atoi(secondsString)
if err != nil {
log.Printf("SLEEP_SECONDS environment variable %q not an int, using default %d seconds\n", secondsString, DEFAULT_SLEEP_SECONDS)
} else {
sleepSeconds = val
}
}
time.Sleep(time.Duration(sleepSeconds) * time.Second)
return mapper.MessagesBuilder().Append(mapper.NewMessage(d.Value()).WithKeys(keys))
}

Expand Down

0 comments on commit dd1b8c4

Please sign in to comment.