RecurringJob.AddOrUpdate

I would like to make a Batch in a WCF service with OWIN.

  • I have an initialization class :

public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration
.UseAutofacActivator(AutofacHostFactory.Container)
.UseBatches()
.UseSqlServerStorage(“ConnexionHangFire”);

app.UseHangfireServer();

In this method, I directly call the method who run the batch :

RecurringJob.AddOrUpdate(“IdJobHangFire”,
x => x.ImporterFichier(“USER”),
getCleEnvironnement(“CronHangFire”));
}

  • And the method :

public void ImporterFichier(string utilisateur)
{
try
{
//code

                var idBatchTrtFiles = BatchJob.StartNew(x =>
                {
                    foreach (string file in files)
                    {
                        x.Enqueue<IGestionImportFichierExpedition>(z => z.traiterFichierColissimo(file, utilisateur));
                    }
                });

                var id2 = BatchJob.ContinueWith(idBatchTrtFiles, x =>
                {
                    //code
                });

When the method is called, in the dashboard, I have this history :

Failed An exception occurred during performance of the job.
Hangfire.CreateBatchFailedException
An exception occurred while creating the batch. See the inner exception for details.
Hangfire.CreateBatchFailedException: An exception occurred while creating the batch. See the inner exception for details. —> System.InvalidOperationException: Batches with zero background jobs are not supported.

Next, the Job is retried and it’s works.

How to resolve this problem ?

Thank you very much for your help, and sorry for my bad english !