4
I’m trying to create an application example that can call a function/method and that after a certain time it checks if the process has already been executed, if not, call the same function/method again and check the previous progress if it is running or is finished and return the process.
I have searched long enough, but I have not found an example that can be followed. The links below describe what Design Patterns - Idempotency Messages actually does.
https://msdn.microsoft.com/pt-br/library/dn589781.aspx
http://blog.jonathanoliver.com/idempotency-patterns/
I’m trying this way;
using System;
namespace Idempotent_Messages
{
public class Program
{
static IdePotencyHelper idePotencyHelper = new IdePotencyHelper();
public static int passo = 1;
static void Main(string[] args)
{
var func = new Funcionario();
var command = new CqrsBase<Int32, Funcionario>();
command.Execute(func);
command.IdPotency((f) =>
{
var funcBanco = new Funcionario();
funcBanco.Id = 1;
return f.Id == funcBanco.Id;
},
(x)=> { return x.Id; }
, func);
}
}
public class Funcionario
{
public int Id { get; set; }
}
public class CqrsBase<T, TArgs>
{
public T Execute(TArgs args)
{
return default(T);
}
}
public static class CqrsBase
{
public static TReturn IdPotency<TReturn, TArgs>(this CqrsBase<TReturn, TArgs> cqrs, Func<TArgs,bool> verify, Func<TArgs, TReturn> existsFunc, TArgs args)
{
var existe = verify(args);
if (existe)
{
return existsFunc(args);
}
else
{
return cqrs.Execute(args);
}
}
}
}
The Design Patterns - Idempotency
An operation is idempotent if it has no additional effects if it is called more than once with the same parameters. You can’t control how your public API is called by your customers, so you should make sure that it doesn’t lead to any unwanted effects if they repeat their calls over and over again.
A common solution is to provide a correlation ID for any potentially state-changed operation. The service checks in some repository if the request has been processed. If yes, the previously stored response must be provided.
Here is a flowchart that shows communication with a correlation identification:
Image copied from the website.
The problem is that I don’t know how to create an identifier for each process to store its status and after the determinant time check the process by the identifier.
It’s not bad, but Voce needs to greatly improve the quality of your code.
– Bruno Costa
in fact, I have to retrieve it completely, in a blog I found a good description of the subject. http://blog.jonathanoliver.com/idempotency-patterns/, but does not have an example of application.
– Marco Souza
@Brunocosta, I made an improved edition , already very close to what I really need.
– Marco Souza
What I don’t understand is what this has to do with repeating tasks after a certain period of time...
– Bruno Costa
You understand the concept of idempotency-Patterns, ??
– Marco Souza
Already knew. Idempotency is not a pattern, but rather a property/feature of certain operation.
– Bruno Costa
get it, revise the concepts then microsoft itself says it’s a Patterns . https://msdn.microsoft.com/pt-br/library/dn589781.aspx
– Marco Souza
No need to read this article. A Wikiedia says right away that Idempotency is a property in the first sentence
... is the property of certain operations in mathematics and computer science
– Bruno Costa
@Brunocosta, okay, what I need is what’s in the article, not what you posted.
– Marco Souza
I edited the answer.
– Bruno Costa