Skip to content

data-miner00/JobScheduling

Repository files navigation

JobScheduling

An example repository for job scheduling in C#.

Directory

  1. JobScheduling.Common: Common shared codes
  2. JobScheduling.Simplest: Simplest scheduling on Quartz
  3. JobScheduling.DependencyInjection: Using Quartz with dependency Injection
  4. JobScheduling.WebApiExample: Using Quartz, background job and WebApi
  5. JobScheduling.HangfireApp: Simplest scheduling on Hangfire
  6. JobScheduling.WebApiExample.HangfireApp: Using Hangfire and WebApi

Details

JobScheduling.Simplest

This example is just a console app that has 1 Quartz job called HelloJob.

flowchart LR
    A[Program] --> B(HelloJob)
Loading

JobScheduling.DependencyInjection

This example includes two Quartz jobs running on different Cron schedule using dependency injection technique.

flowchart TD
    A[Program] --> B(FirstJob)
    A[Program] --> C(SecondJob)
Loading

JobScheduling.WebApiExample

This example illustrates running a WebAPI project alongside with background service and Quartz Cron Jobs.

flowchart TD
    A[Program] --> F(WebApi)
    A[Program] --> B(LogBackgroundService)
    A[Program] --> C(QuartzBackgroundService)
    C --> D(FirstJob)
    C --> E(SecondJob)
Loading

Example of the logs in the console:

Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:42:14 - 0 0/1 * 1/1 * ? *
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7042
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5281
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\Workspace\Visual Studio\JobScheduling\JobScheduling.WebApiExample
info: JobScheduling.WebApiExample.Controllers.WeatherForecastController[0]
      Get weather called
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:42:24 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:42:34 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:42:44 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:42:54 - 0 0/1 * 1/1 * ? *
Executing Second Job: 09/16/2024 08:43:00
Executing First Job: 09/16/2024 08:43:00
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:43:04 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:43:14 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:43:24 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:43:34 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:43:44 - 0 0/1 * 1/1 * ? *
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:43:54 - 0 0/1 * 1/1 * ? *
Executing First Job: 09/16/2024 08:44:00
Executing Second Job: 09/16/2024 08:44:00
Logging from LogBackgroundService - ExecuteAsync - 09/16/2024 08:44:04 - 0 0/1 * 1/1 * ? *

JobScheduling.WebApiExample.HangfireApp

This example illustrates running a WebAPI project alongside with Hangfire queue, scheduling and recurring Cron Jobs.

flowchart TD
    A[Program] --> F(WebApi)
    F --> C(job endpoint)
    C --> D(Queue)
    C --> E(Schedule)
    C --> G(Recurring)
Loading

Resources

About

Job scheduling examples with C#

Topics

Resources

License

Stars

Watchers

Forks

Languages