Recurring Job for Complex Functions


I am trying to use HangFire for a function that makes some complex jobs like consuming external webservices, process data and save in database.

Here is my Startup.cs

 public class Startup
    public void Configuration(IAppBuilder app)
    /// Setting the Pooling interval for SQL Server
    var sqlServerOptions = new SqlServerStorageOptions
        QueuePollInterval = TimeSpan.FromSeconds(15)

    var queueOptions = new BackgroundJobServerOptions
        Queues = new[] { "critical", "default" }

    GlobalConfiguration.Configuration.UseSqlServerStorage("Context", sqlServerOptions);


    HomeController home = new HomeController();


And this is the start function

 public void Start()
    CompanyMatch = new CompanyMatchModel();
    var LinkedCompList = CompanyMatch.GetLinkedComp();
    Context db = new Context();
    OrderModel order = new OrderModel();

    if (LinkedCompList.Count() != 0)

        foreach (var companyMatch in LinkedCompList)

            companyMatch.Company = db.Company.Include(u => User).First(sap => sap.DBName.Equals(companyMatch.Company.DBName));
            companyMatch.EcommerceModel = db.Ecommerce.Include(p => p.Platform).First(e => e.SiteName.Equals(companyMatch.EcommerceModel.SiteName));
            RecurringJob.AddOrUpdate("ImportTdoBdbId", () => OrderModel.ImportOrdersToDb(companyMatch), "*/3 * * * *");
            RecurringJob.AddOrUpdate("UpdateOrdersNfId", () => OrderModel.UpdateOrdersNfeKey(companyMatch.SAPCompany), "*/5 * * * *");
            RecurringJob.AddOrUpdate("UpdateXmlSHLId", () => OrderModel.UpdateXmlSHL(companyMatch.SAPCompany), "*/7 * * * *");


        RecurringJob.AddOrUpdate("ImportOrders", () => order.ImportOrders(), "*/5 * * * *");

I have added some Debug.Print in the internal functions of those methods and what I noticed is that HangFires pass thru all of them but does not execute the operations. Inside each of the functions added in Queue there are sub functions that collect data, loops to validate them and database insertings.

Does HangFire supports these kinds of operation or it has some limitation in this scenario?

What do you mean? Does it print a debug message?

This operations are regular, don’t see any problems with them.



Debug.Print(“Start the Operation”);

importOrders( params …) ;

Debug.Print(“End of the Operation”);

The importOrders is a function that takes some seconds to be finished, but when I used HangFire it seems the importOrders was ignored and both the beginning and ending of the the class were executed.

But, I have found a problem in the system today, I will fix it and then try with HangFire again.

If the final method was executed, and you are being the “End of the Operation” message, then all the previous lines were executed also. Check your importOrders methods.