Skip to content

Commit

Permalink
Merge pull request #1545 from 0chain/hotfix/remove-sleep
Browse files Browse the repository at this point in the history
Remove sleep in add web workers and return bool in createWorkers
  • Loading branch information
dabasov authored Jun 29, 2024
2 parents 7eaea0c + b3a6c96 commit b55cbcc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 4 additions & 4 deletions wasmsdk/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func multiUpload(jsonBulkUploadOptions string) (MultiUploadResult, error) {
result.Success = false
return result, errors.New("Error fetching the allocation")
}
addWebWorkers(allocationObj)

operationRequests := make([]sdk.OperationRequest, n)
for idx, option := range options {
wg := &sync.WaitGroup{}
Expand Down Expand Up @@ -1019,12 +1019,12 @@ func terminateWorkersWithAllocation(alloc *sdk.Allocation) {
}
}

func createWorkers(allocationID string) {
func createWorkers(allocationID string) bool {
alloc, err := getAllocation(allocationID)
if err != nil {
return
return false
}
addWebWorkers(alloc)
return addWebWorkers(alloc)
}

func startListener() error {
Expand Down
15 changes: 7 additions & 8 deletions wasmsdk/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"time"

"github.com/0chain/gosdk/core/sys"
"github.com/0chain/gosdk/wasmsdk/jsbridge"
"github.com/0chain/gosdk/zboxcore/client"
"github.com/0chain/gosdk/zboxcore/sdk"
Expand Down Expand Up @@ -67,17 +66,17 @@ func reloadAllocation(allocationID string) (*sdk.Allocation, error) {
return it.Allocation, nil
}

func addWebWorkers(alloc *sdk.Allocation) {
func addWebWorkers(alloc *sdk.Allocation) (isCreated bool) {
c := client.GetClient()
if c == nil || len(c.Keys) == 0 {
return
}
isCreated := false

for _, blober := range alloc.Blobbers {
_, isCreated, _ = jsbridge.NewWasmWebWorker(blober.ID, blober.Baseurl, c.ClientID, c.Keys[0].PublicKey, c.Keys[0].PrivateKey, c.Mnemonic) //nolint:errcheck
}
// wait for worker to be instantiated
if isCreated {
sys.Sleep(1 * time.Second)
_, workerCreated, _ := jsbridge.NewWasmWebWorker(blober.ID, blober.Baseurl, c.ClientID, c.Keys[0].PublicKey, c.Keys[0].PrivateKey, c.Mnemonic) //nolint:errcheck
if workerCreated {
isCreated = true
}
}
return
}

0 comments on commit b55cbcc

Please sign in to comment.