Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Background Job run in Windows service schedule through web application #11221


User avatar
0
adamphones created

Hi,

As the background jobs are running in Application pool and this might cause issues if the tasks are taking too long and some reason application pool decides to shut itself. We want to run those backgroun jobs in a window service. This part can be achieved by introducing Configuration.BackgroundJobs.IsJobExecutionEnabled = true; in Windows service module.

The article about jobs has the following sections:

  • You can enable job execution for only one instance of the application.
  • You can disable job execution for all instances of the web application and create a separated, standalone application (example: a Windows Service) that executes background jobs.

We are planning to go ahead the second option ( move background jobs running into Windows service). However, would that be a way to still manage those jobs through web application? For instance we would sometimes want to force to run the background jobs or rescedule the jobs. I have done a demo and that didn't work as web application sets Configuration.BackgroundJobs.IsJobExecutionEnabled = false;.

The question is: Can we manage background jobs through web application but jobs run in windows service? If yes how would we achieve that?

Update

In your documantation you separated Background Jobs and Background Workers. Backgorund jobs are persisted in the table AbpBackgroundJobs automatically. This is great to use in web application. However both Background jobs and Background workers are enabled with the same key Configuration.BackgroundJobs.IsJobExecutionEnabled = false;. Is this correct?

Background jobs should run in application pool as those are short tasks like sending emails etc.There should be a way to separate between Background Jobs from Background workers. For instance this would allow to move Background workers to be moved out of Application pool into Windows Service.

Q2: Does AbpBackgroundJobs table is also used to persist Backround Workers? What if we want to use advanced scheduling with Quartz? How can we persist the jobs in the database? Would they also be stored in the same table? Or we would need to configure Quartz somewhere to make sure new table is created for it automatically to persist the jobs? If yes then how could we do that? Having [DependsOn(typeof (AbpQuartzModule))] does bring all in place? How can we configure the persistent store?

This might feel like too many questions( Apologies :)). But we really need to move long tasks outside of Application pool and also be able to manage those tasks from web application( manually run them from web application, paused them etc).

Regards


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @adamphones

    Sorry for the late reply. As you stated, BackgroundJobs are stored in DB and you can start a background job in the web app and your windows service will execute it.

    On the other hand, background workers are not stored in DB, so you can't manage them from the web app. For advanced scheduling, you need to use Quartz or Hangfire. Considering your case, Quartz might be a better choice. It store's its background worker info in database I guess.

  • User Avatar
    0
    adamphones created

    Hi Ismail,

    Do both Bakground Jobs and Bakground Workers are enabled with the same key Configuration.BackgroundJobs.IsJobExecutionEnabled = false;?

    Is there any example that Background Jobs can be controlled in web app but can be executed in a Windows Service? How could this be achieved really?

    If we want to use Quartz along side Background Jobs then can we enable disable them independently? Or we need to choose either use Background Jobs or Background Workers?

    Thanks,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @adamphones

    Do both Bakground Jobs and Bakground Workers are enabled with the same key Configuration.BackgroundJobs.IsJobExecutionEnabled = false;?

    Yes

    Is there any example that Background Jobs can be controlled in web app but can be executed in a Windows Service? How could this be achieved really?

    We don't have such a sample but basically you need to insert records to BackgroundJobs table using https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers#add-a-new-job-to-the-queue. Then, if your Windows Service is using same database, it will try to execute the job.

    If we want to use Quartz along side Background Jobs then can we enable disable them independently? Or we need to choose either use Background Jobs or Background Workers?

    You can use them together. ABP's default Quartz integration also uses Configuration.BackgroundJobs.IsJobExecutionEnabled. So, if you want to enable/disable them independently, you can directly use Quartz and skip ABP's Quartz integration.