Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this the way ? #86

Open
walshe opened this issue Apr 24, 2022 · 1 comment
Open

Is this the way ? #86

walshe opened this issue Apr 24, 2022 · 1 comment

Comments

@walshe
Copy link

walshe commented Apr 24, 2022

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)
            }
            
        })


        
    })
@RaymondCrandall
Copy link

https://stackoverflow.com/questions/55031780/nodejs-retry-function-if-failed-x-times

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants