JustScheduler 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JustScheduler --version 0.1.0                
NuGet\Install-Package JustScheduler -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JustScheduler" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JustScheduler --version 0.1.0                
#r "nuget: JustScheduler, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JustScheduler as a Cake Addin
#addin nuget:?package=JustScheduler&version=0.1.0

// Install JustScheduler as a Cake Tool
#tool nuget:?package=JustScheduler&version=0.1.0                

JustScheduler

.NET Core Background Scheduler that supports multiple backends for 21st century! Built on HostedServices and supports dependency injection that is already present on your application!

Sample project can be found at samples\JustScheduler.SampleWeb directory.

Simple Job

public class HelloWorldBackgroundService : IJob {
  private readonly DbContext db;

  public HelloWorldBackgroundService(DbContext db) {
		this.db = db;
  }

  public async Task Run() {
		Console.WriteLine("Hello world!");
  }
}

Generic Event Job

public class SomeEventService : IJob<SomeEvent> {
  private readonly DbContext db;

  public SomeEventService(DbContext db) {
		this.db = db;
  }

  public async Task Run(SomeEvent e) {
		Console.WriteLine(e.message);
  }
}

Generic Data Source

public class RabbitMqPooler : IDataSource<SomeEvent> {
  private readonly RabbitMqService rabbitMqService;

  public SomeEventService(RabbitMqService rabbitMqService) {
		this.rabbitMqService = rabbitMqService;
  }

  public async IAsyncEnumarable<SomeEvent> Run(CancellationToken ct) {
		while(!ct.IsCancellationRequested) {
			var data = await es.PoolData(ct);
			yield return data;
		}
  }
}

Startup configuration

public void ConfigureServices(IServiceCollection services) {
  services.AddJustScheduler(builder => {
		builder
			.WithRunner<HelloWorldBackgroundService>()

			// skip this if you want HelloWorldBackgroundService to be constructed
			// every time it is scheduled to run
			// .UseSingletonPattern()

			.ScheduleEvery(TimeSpan.FromSeconds(10))
			.ScheduleOnce()
			.InjectTrigger()
			.Build();

		builder
			.WithParameterRunner<SomeEventService, SomeEvent>()

			// skip this if you want SomeEventService to be constructed
			// every time it is scheduled to run
			// .UseSingletonPattern()

			// Run the service with these parameters
			// on the application start
			.ScheduleOnce(new SomeEvent("Hello world! 1st run."))
			.ScheduleOnce(new SomeEvent[] {
				new SomeEvent("Hello world! 2st run."),
				new SomeEvent("Hello world! 3rd run.")
			})

			// Injects IJobTrigger<SomeEventService, SomeEvent> to DI
			// so you can pass data to the background worker
			// from your controller or services!
			.InjectTrigger()

			// Initializes RedisDataSource and listens for incoming job
			// you can add multiple datasources per background service!
			.AddDataSource<RedisDataSource>()

			.Build();
		);
	});

	// the rest of the configure function
}

Inside a controller

public class SomeController : Controller {
  private readonly IJobTrigger<SomeEventService, SomeEvent> someEventService;
  private readonly IJobTrigger<SomeParameterlessBackgroundService> helloWorldTrigger;

  public SomeController(
		IJobTrigger<SomeEventService, SomeEvent> someEventService,
		IJobTrigger<HelloWorldBackgroundService> helloWorldTrigger
  ) {
		this.helloWorldTrigger = helloWorldTrigger;
		this.someEventService = someEventService;
  }

  [HttpGet("/postjob")]
  public bool PostJob(string message) {
		SomeEventService.Run(new SomeEvent(message)); // it queues the event to run 
																									// on the background!
  }

  [HttpGet("/checkresults")]
  public bool PostJob(string message) {
		SomeParameterlessService.Run(); // it queues the event to run
																		// on the background!
  }
}

License

© 2019 Burak Tamturk

Released under the MIT LICENSE

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.1 134 11/19/2024
0.5.0 78 11/18/2024
0.4.0 322 11/17/2023
0.3.6 369 1/17/2023
0.3.5 877 11/8/2022
0.3.3 195 9/18/2022
0.3.2 421 11/10/2021
0.3.1 680 11/11/2020
0.3.0 461 11/11/2020
0.2.1 464 9/21/2020
0.2.0 509 5/13/2020
0.1.1 625 10/13/2019
0.1.0 563 10/12/2019