Hi,
Our hangfire implementation loads binaries via reflection, when an error occurs in this activated class, the Hangfire windows service stops and the job is set to succeeded. I can see the error in the windows event logs, but Hangfire thinks the job is finished.
If I trigger an exception by activating the binaries, Hangfire correctly logs this error and sets the job as faulted, but when an error occurs in the activated class,Hangfire sets the job as finished
Service:
`partial class Processor : ServiceBase
{
private BackgroundJobServer _server;
public Processor()
{
InitializeComponent();
GlobalConfiguration.Configuration.UseSqlServerStorage("Hangfire");
GlobalJobFilters.Filters.Add(new ProlongExpirationTimeAttribute());
}
protected override void OnStart(string[] args)
{
_server = new BackgroundJobServer();
}
protected override void OnStop()
{
_server.Dispose();
}
}`
Factory for activating types
`public static class HangFireFactory
{
public static IHangFireJob GetJobImplementation(string jobName, params object [] args)
{
if (!HangfireJobs.AvailableJobs.ContainsKey(jobName.ToLower()))
{
throw new NullReferenceException($“Cannot get the info for job {jobName}”);
}
var availableJob = HangfireJobs.AvailableJobs[jobName.ToLower()];
var directoryInfo = new FileInfo(new Uri(typeof (HangFireFactory).Assembly.CodeBase).AbsolutePath).Directory;
if (directoryInfo == null){throw new ArgumentException("Directory not found");}
var directoryName = directoryInfo.FullName;
var fullPath = Path.Combine(directoryName, availableJob.Location, availableJob.AssemblyName);
var assembly = Assembly.LoadFrom(Uri.UnescapeDataString(fullPath));
var jobType = assembly.GetTypes().First(t => t.Name == availableJob.Type);
return Activator.CreateInstance(jobType, args) as IHangFireJob;
}
}`
Generic executor
public class HangFireJob { public void ExecuteJob(string job, params object[] arguments) { using (var impl = HangFireFactory.GetJobImplementation(job, arguments)) { impl.DoTheWork(); } } }