Tuesday, January 11, 2011

Retrying Code Execution

I have a bit of code I'm working on at work that makes use of an HTTP endpoint to notify a legacy system of certain events. Because the network is not reliable, we have to handle the case when the network may be down. In this situation, it means to try again a few times, after which the processing request goes into an error queue, where it can be handled manually. So, I started out with something like this:

This calls the HTTP endpoint up to five times. If one of those times succeeds, it returns the result and stops trying. If it gets to the sixth time, it gives up.

Now, in my project, I have several of these types of calls to make. Much of the above code, namely the exception handling and flow control stuff, is common to all of them. So, using some functional .NET and an extension method, we can do this:

This will attempt to execute and return the value of func up to times times, and give up after that. With this extension method, we can now put our endpoint-calling code in a Func<int> and tell it to try to call the endpoint up to five times, like this: Now, is this the best way to do this? Maybe; maybe not. It's just something I've been toying around with in my attempts to eliminate duplication of the aforementioned ugly flow control code. I'll have to walk around in these shoes for a while and see whether I like them.

12 comments:

Anjudevan said...

Really informative Blog...Thanks for sharing...Waiting for next update...
Wordpress Training in Chennai
Wordpress Training
wordpress course fees
wordpress training in vadapalani
wordpress training in Guindy
Struts Training in Chennai
clinical sas training in chennai
Spring Training in Chennai
Photoshop Classes in Chennai
LoadRunner Training in Chennai

Riya Raj said...
This comment has been removed by the author.
sanjandevan said...

awesome article,the content has very informative ideas, waiting for the next update...
javascript training in chennai
javascript training center in chennai
javascript classes in chennai
javascript training in anna nagar
javascript training in vadapalani
javascript training in chennai
core java training in chennai
Photoshop Classes in Chennai
Manual Testing Training in Chennai
Drupal Training in Chennai

Riya Raj said...

The blog which you have shared is more creative... Waiting for your upcoming data...
Python Training in Chennai
Python course in Chennai
Python Training
Best Python Training Institute in Chennai
Python Training in Velachery
Python training in Adyar
Hadoop Training in Chennai
Software testing training in chennai
JAVA Training in Chennai

Sivanandhana Girish said...

Really wonderful blog! Thanks for taking your valuable time to share this with us. Keep us updated with more such blogs.
AWS Training in Chennai
AWS Training
AWS Training institute in Chennai
DevOps Training in Chennai
Azure Training in Chennai
VMware Training in Chennai
AWS Training in Velachery
AWS Training in Tambaram
AWS Training in Tnagar
AWS Training in Anna nagar

vinudevan said...

Thanks for giving excellent Message. Waiting for the next article
DOT NET Training in Chennai
DOT NET Course Chennai
dot net institute in chennai
best dotnet training in chennai
dot net training in Porur
Html5 Training in Chennai
Spring Training in Chennai
Struts Training in Chennai
Wordpress Training in Chennai
SAS Training in Chennai

Vivek Vichu said...

Nice Blog...Thanks for sharing the article waiting for next update...
Artificial Intelligence Course in Chennai
best artificial intelligence training in chennai
C C++ Training in Chennai
javascript training in chennai
Html5 Training in Chennai
QTP Training in Chennai
Spring Training in Chennai
DOT NET Training in Chennai

vinudevan said...

Thanks for giving excellent Message. Waiting for the next article
DOT NET Training in Chennai
DOT NET Course Chennai
dot net institute in chennai
best dotnet training in chennai
dot net training in Porur
Html5 Training in Chennai
Spring Training in Chennai
Struts Training in Chennai
Wordpress Training in Chennai
SAS Training in Chennai

Sreyas Ram said...

awesome article,the content has very informative ideas, waiting for the next update...
Study Abroad Consultants in Kerala
study abroad consultants in thrissur
Study Abroad Consultants in Calicut
abroad job consultancy in coimbatore
Abroad Education Consultants in Coimbatore
europe job consultancy in coimbatore
study abroad
study in poland
study in europe
free masters in germany

subha said...

Are you trying to move in or out of Jind? or near rohtak Find the most famous, reputed and the very best of all Packers and Movers by simply calling or talking to Airavat Movers and Packers
good jobs guys
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai

Unknown said...

Nice! you are sharing such helpful and easy to understandable blog. i have no words for say i just say thanks because it is helpful for me.




Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

Tanika Co Valda said...

The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. machine learning projects for final year In case you will succeed, you have to begin building machine learning projects in the near future.

Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.


Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

Post a Comment