Azure storage tables: can we forget about asynchronous methods?

I have a method in my MVC web app that clears old data from Azure table storage, such as abandoned user sessions. I am doing my work in TableBatchOperation

objects that I do with CloudTable.ExecuteBatchAsync

. I don't have to wait for the results, and if the operation doesn't work for some reason, like a network problem, it doesn't matter, because I can just try again later. Is it possible to just call the method without await

or anything else and get away?

So this code will cause problems?

List<TableBatchOperation> batches = { ... }
foreach (TableBatchOperation batch in batches) {
    table.ExecuteBatchAsync(batch);
}

// Method ends here

      

Or do I need to grab all the returned objects and call Wait()

on them?

+3


source to share


1 answer


You can do it in the sense that it works and does what you want. You don't care about the possibility of a job being lost.

You probably still want to handle errors and keep a log. Imagine that you have misconfigured the storage and all work items are down. You probably want to know about this.



Wrap table.ExecuteBatchAsync(batch)

in an async function where you catch and log exceptions. Cancel the task returned by this function. (Alternatively, add a continuation, but I find it worse than code.)

Also note that the resource uses it indefinitely. If this cycle is repeated many times, then many operations are suspended or started at the same time. This could be a problem. If you are expecting a low load, this is acceptable for this risk.

+2


source







All Articles