I have a job consisting of two parts, called in the following manner
var jobId = BackgroundJob.Enqueue(() => DataImportService.Run(null, filepath, path, User.Identity.Name));
BackgroundJob.ContinueWith(jobId, () => DataImportService.Notify(null, User.Identity.Name));
The bodies of which are something like
[DisableConcurrentExecution(60)]
public static DataImportSummary Run(PerformContext context, string fileName, string path, string userName)
{
DataImportService importService = new DataImportService(new DataImportRepository(), path);
DataImportSummary result = importService.StartDataImport(fileName, userName);
if (context != null)
{
if (!context.Items.ContainsKey("importId"))
{
context.Items.Add("importId", result.Id);
}
else
{
context.Items["importId"] = result.Id;
}
}
return result;
}
[AutomaticRetry(Attempts = 0)]
[DisableConcurrentExecution(60)]
public static void Notify(PerformContext context, string userName)
{
try
{
// Do stuff
}
catch (InvalidOperationException ex)
{
logger.Debug(ex);
if (context.Items.ContainsKey("importId"))
{
logger.Debug("ImportId: {0}", context.Items["importId"]);
int importId = (int)context.Items["importId"];
LogImportException(importId, ex);
}
}
}
}
My expectation was that since I put something in the Items collection in the Run method it would be there in the subsequent call to Notify but this is not the case and the Items collection does not contain a key named “importId”
Any help would be appreciated