Debian Codegraph @

examples/distributed-early-refreshes/main.go

raw
1 package main
2
3 import (
4 "context"
5 "log"
6 "sync"
7 "time"
8
9 "github.com/viccon/sturdyc"
10 )
11
12 var ids = []string{"1111", "2222", "3333"}
13
14 // launchContainer will simulate having a container that runs
15 // its own in-memory cache, but shares a distributed storage.
16 func launchContainer(containerIndex int, storage sturdyc.DistributedStorageWithDeletions) {
17 apiClient := newAPIClient(storage)
18 for i := 0; i < 100; i++ {
19 _, err := apiClient.GetShippingOptions(context.Background(), containerIndex, ids, "asc")
20 if err != nil {
21 log.Fatal(err)
22 }
23 log.Println("Container", containerIndex, "finished fetching shipping options")
24 time.Sleep(100 * time.Millisecond)
25 }
26 }
27
28 func main() {
29 distributedStorage := newDistributedStorage()
30 numContainers := 5
31
32 wg := &sync.WaitGroup{}
33 wg.Add(numContainers)
34 for i := 0; i < numContainers; i++ {
35 go func() {
36 launchContainer(i+1, distributedStorage)
37 wg.Done()
38 }()
39 time.Sleep(50 * time.Millisecond)
40 }
41 wg.Wait()
42 }