Skip to content

Is this the way ? #86

Open
Open

Description

@walshe

Does this look like a reasonably safe use of retry?. I am trying to implement a 2-3 attempt retry when something goes awry in my redis subscriber. If it fails after max attempts I will just save to a dead letter queue table in my database (or raise some sort of alert if the the db save fails :))

pubsub.subscribe(`TEST`, async(message) => {
        console.log("processing...", message )

        var operation = retry.operation({
            retries: 2,
            factor: 2,
            minTimeout: 1 * 1000,
            maxTimeout: 60 * 1000,
            randomize: false,
          });

        return operation.attempt(async(currentAttempt) => { 
            console.log("currentAttempt is",currentAttempt)
            
            let err
            try{
                
                //my logic that might fail and throw an error goes here


            }catch(whoops){
                err = whoops
            }

            if (operation.retry(err)) {
                console.log('returning for a retry...')
                return;
            }

            
            if(operation.mainError()){
                console.log("There was a persistent error, we should save message to a DLQ here:" ,operation.mainError().message)
            }
            
        })


        
    })

Activity

  1. RaymondCrandall commented on Jan 28, 2023

    @RaymondCrandall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions