Is it a good idea to put the Enqueue method in an async wrapper and have my API controller call it that way?
Which is better and why?
Synchronously:
public IActionResult AddLogs(List<Log> logs)
{
BackgroundJob.Enqueue(() => DM.AddLogsBackground(logs));
return Ok();
}
Async:
public async Task<IActionResult> AddLogs(List<Log> logs)
{
await DM.AddLogs(logs);
return Ok();
}
public async Task AddLogs(List<Log> logs)
{
BackgroundJob.Enqueue(() => AddLogsBackground(logs));
}
The documentation says:
The Enqueue method does not call the target method immediately, it
runs the following steps instead:
- Serialize a method information and all its arguments.
- Create a new background job based on the serialized information.
- Save background job to a persistent storage.
- Enqueue background job to its queue.