Hi! I have a problem with sending CancellationToken, I use Hangfire.AspNetCore 1.7.9 and .NetCore 3.1.1
When I click to DeleteJob in admin panel, job deletes and I no longer get into breakpoints inside the job. It seems that Hangfire kills my Job without sending CancellationToken. And that’s a problem because I am checking Token to kill exeternal process which this job starts
Below the part of job code:
[DisplayName("{1}")]
public async Task ExecuteAsync(string filePath, string jobName, string parameters, CancellationToken cancellationToken)
{
var process = CreateProcess(filePath, parameters);
try
{
process.Start();
_backLogger.LogInformation($"Process with id \"{process.Id}\" has been started");
}
catch (InvalidOperationException ex)
{
_backLogger.LogError(ex, "Something went wrong with starting process, it seems that you don't have enough rights to start new process");
throw;
}
catch (Win32Exception ex)
{
_backLogger.LogError(ex, "Something went wrong with starting process, it seems that you don't have enough rights to folder with \"filePath\" job exe file or path does not exist");
throw;
}
catch (Exception ex)
{
_backLogger.LogError(ex, "Something went wrong with starting process of BackgroundJob");
}
while (!cancellationToken.IsCancellationRequested && !process.HasExited)
{
await Task.Delay(WaitTimeMilliseconds, cancellationToken);
}
if (cancellationToken.IsCancellationRequested)
{
_backLogger.LogInformation($"Process with id \"{process.Id}\" will be killed");
process.Kill();
_backLogger.LogInformation($"Process with id \"{process.Id}\" has been killed");
}
And code which adds job to queue:
}
else if (job.Type == JobType.Background)
{
BackgroundJob.Enqueue(j => j.ExecuteAsync(job.FilePath, job.Name, job.JobParameters, CancellationToken.None));
}