RSCG- Idempotency- Idea and implementation

Everyone is talking about idempotency ( Idempotence – Wikipedia  ) . So it should be easy to implement as a code generator – just having an attribute to apply ?

One more thing: if we store the values, then somehow , after some time, we  should clean (maybe after 1 year ? )

So the workflow is

In your C# method, apply the [Idempotent] attribute to parameters you want to track:

public void ProcessData([Idempotent] string input, int retry)
    {
  if (ProcessData_ExistsBefore(input))
    {
        // This input was already processed , your choice to return
        //or generate an exception
        // your choice
        Console.WriteLine("Duplicate detected, skipping");
        return;
    }
        // Your implementation here
    }

The generator will generate the

NAMEFUNCTION_ExistsBefore ( e.g. ProcessData_ExistsBefore ) – to see if it exists before
NAMEFUNCTION_DeletePreviousData ( e.g. ProcessData_DeletePreviousData ) –

Also, it puts an ConcurrentDictionary to remember the entries and a TimeProvider to be tested .
The final product is at https://www.nuget.org/packages/RSCG_idempotency and the site is at ignatandrei/RSCG_idempotency: Adding idempotency to any function by Roslyn


Posted

in

, ,

by

Tags: