Hangfire 1.6.8 Long running job restarts after 20 min when scheduled


#1

Hi,

We are using Hangfire 1.6.8
Hangfire.Core
Hangfire.SqlServer

It runs in IIS on a windows server 2008 with SQL Server 2008 as storage

We use RecurringJob only and create new AppDomains for each job
Everything works great generally, with one exception…

We have one job that takes around 2 hours to run.
If we trigger the run manually (through Hangfire) or just run the .exe-file from the filesystem it runs without any problems.
But when it runs through the scheduler (once every 12 hours) it restarts around every 20 minutes

The job produces log-files and it catches ThreadAbortException and logs them as it is being shut down
System.Threading.ThreadAbortException: Thread was being aborted.

there is a similar issue like this in the forum already but it was suppoed to be resolved in an earlier version
http://github.com/HangfireIO/Hangfire/issues/514

this is how a manual call looks like in the dashboard

but a failed call looks like this, and it keeps going until i delete it

Anyway, here comes some code-pieces for how we run our jobs

RecurringJob.AddOrUpdate(package.PackageName,
                    () => RecurringWorker.Run(package.PackageName, package.PackageID),
                    cron, 
                    TimeZoneInfo.Local);
public class RecurringWorker
    {
        [DisplayName("{0}")]
        public static void Run(string name, int packageId)
        {
            PackageRepository pr = new PackageRepository();
            var package = pr.GetPackageByID(packageId);

            var setup = new AppDomainSetup();
            setup.ApplicationBase = Path.GetDirectoryName(package.ExeLocation);
            setup.PrivateBinPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            setup.AppDomainInitializer = new AppDomainInitializer(Seb.Wsd.IEMv2.AppDomainInitializer.Initializer);
            setup.AppDomainInitializerArguments = new string[] { package.ExeLocation, packageId.ToString(), package.ExeArguments };
            var domain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), AppDomain.CurrentDomain.Evidence, setup);
            AppDomain.Unload(domain);
        }       
    }

#2

Were you able to get past this, I’m running into a similar situation (I am on version 1.6.17)

Is there something in the Hangfire.BackgroundJobServerOptions we need to extend for long running jobs?