Skip to content

Commit

Permalink
Merge pull request #18 from moonstream-to/quick-fix-moonstream-drop-i…
Browse files Browse the repository at this point in the history
…ssues

`waggle moonstream drop` is now idempotent on a per infile basis
  • Loading branch information
zomglings authored Sep 16, 2023
2 parents 6da8043 + ea723be commit 6e7c07d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func CreateMoonstreamCommand() *cobra.Command {
}

var blockchain, address, contractType, contractId, contractAddress, infile string
var limit, offset, batchSize int
var limit, offset, batchSize, retries int
var showExpired bool

contractsSubcommand := &cobra.Command{
Expand Down Expand Up @@ -495,7 +495,7 @@ func CreateMoonstreamCommand() *cobra.Command {
}
}

err := client.CreateCallRequests(contractId, contractAddress, limit, callRequests, batchSize)
err := client.CreateCallRequests(contractId, contractAddress, limit, callRequests, batchSize, retries)
return err
},
}
Expand All @@ -504,6 +504,7 @@ func CreateMoonstreamCommand() *cobra.Command {
createCallRequestsSubcommand.Flags().IntVar(&limit, "ttl-days", 30, "Number of days for which request will remain active")
createCallRequestsSubcommand.Flags().StringVar(&infile, "infile", "", "Input file. If not specified, input will be expected from stdin.")
createCallRequestsSubcommand.Flags().IntVar(&batchSize, "batch-size", 100, "Number of rows per request to API")
createCallRequestsSubcommand.Flags().IntVar(&retries, "retries", 1, "Number of retries for failed requests")

moonstreamCommand.AddCommand(contractsSubcommand, callRequestsSubcommand, createCallRequestsSubcommand)

Expand Down
9 changes: 4 additions & 5 deletions moonstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (client *MoonstreamEngineAPIClient) sendCallRequests(requestBodyBytes []byt
return nil
}

func (client *MoonstreamEngineAPIClient) CreateCallRequests(contractId, contractAddress string, ttlDays int, specs []CallRequestSpecification, batchSize int) error {
func (client *MoonstreamEngineAPIClient) CreateCallRequests(contractId, contractAddress string, ttlDays int, specs []CallRequestSpecification, batchSize, retries int) error {
if contractId == "" && contractAddress == "" {
return fmt.Errorf("you must specify at least one of contractId or contractAddress when creating call requests")
}
Expand Down Expand Up @@ -264,9 +264,8 @@ func (client *MoonstreamEngineAPIClient) CreateCallRequests(contractId, contract
}

sendReTryCnt := 1
maxSendReTryCnt := 3
SEND_RETRY:
for sendReTryCnt <= maxSendReTryCnt {
for sendReTryCnt <= retries {
sendCallRequestsErr := client.sendCallRequests(requestBodyBytes)
if sendCallRequestsErr == nil {
break SEND_RETRY
Expand All @@ -275,8 +274,8 @@ func (client *MoonstreamEngineAPIClient) CreateCallRequests(contractId, contract
sendReTryCnt++
time.Sleep(time.Duration(sendReTryCnt) * time.Second)

if sendReTryCnt > maxSendReTryCnt {
return fmt.Errorf("failed to send call requests")
if sendReTryCnt > retries {
fmt.Printf("failed to send call requests")
}
}

Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

var WAGGLE_VERSION = "0.1.2"
var WAGGLE_VERSION = "0.1.3"

0 comments on commit 6e7c07d

Please sign in to comment.