Coravel Documentation

repository·master·Indexed 26 days ago

https://github.com/jamesmh/coravel

A lightweight, modern .NET library for implementing advanced application features such as task scheduling, queuing, caching, mailing, and event broadcasting using a fluent syntax. Includes a dedicated CLI tool (coravel-cli) for installation and scaffolding of invocables, mailables, and events. Supports .NET Core 2.1.0+ and .NET Standard projects.

Tokens
10.9K
Snippets
45
Records
85
Agent score
87%

What's inside Coravel

  1. Overview of Coravel Pro

    master

    Coravel Pro is a professional admin panel and suite of visual tools designed to integrate into .NET Core applications. It provides advanced management capabilities for Coravel users, specifically those working with EF Core.

    Key features include:

    • Database persisted scheduling: Ensures scheduled tasks survive application restarts.
    • Job/Invocable Management UI: A visual interface to manage your background jobs and invocables.
    • Health Metrics Dashboard: Monitor the health and performance of your application.
    • Tabular Reports: Easily configured reports of your data with support for aggregation and complex projections.
  2. Overview of Coravel features

    master

    Coravel is a library for .NET Core applications that provides a simple, expressive, and fluent syntax for implementing advanced application features. Key features include:

    • Task Scheduling: Define recurring tasks directly in code using a fluent syntax, replacing the need for external cron jobs or Windows Task Scheduler.
    • Queuing: A zero-configuration, in-memory queue used to offload long-running tasks to the background.
    • Caching: An easy-to-use API for caching, supporting in-memory storage by default and database drivers for robust scenarios.
    • Event Broadcasting: Facilitates building loosely coupled, maintainable applications.
    • Mailing: A comprehensive mailing system featuring Razor template support, visual testing capabilities, and multiple drivers (SMTP, local log file, or custom 'BYOM' drivers).
  3. Overview of Coravel Mailer

    master
    Coravel Mailer is a specialized package for the Coravel ecosystem designed to simplify email operations in .NET Core applications. It provides a simple and expressive API for sending emails, supports Razor templates for email content, and allows for visual rendering of emails for testing purposes.
  4. Get started with Coravel

    master
    Coravel is a .NET library designed for ease of use and near-zero configuration, allowing you to focus on application logic rather than infrastructural boilerplate. It provides features such as Task/Job Scheduling, Queuing, Caching, Event Broadcasting, and Mailing.
  5. Explore Coravel Pro for EF Core

    master

    Coravel Pro is an admin panel and toolset designed for .NET Core applications using EF Core. It provides features such as:

    • Visual job scheduling and management.
    • CRUD UI scaffolding for managing EF Core entities.
    • Dashboard configuration for displaying health metrics.
    • Custom tabular reports for data management.
  6. Quick-Start: Set up a Coravel Task Scheduler in a Worker Service

    master

    You can quickly set up a worker service that executes tasks at scheduled intervals by registering the scheduler in your service collection and using UseScheduler to define your tasks.

    Note: This example requires Microsoft.Extensions.Hosting and Coravel packages.

    using Coravel;
    
    Console.OutputEncoding = System.Text.Encoding.UTF8;
    
    var builder = Host.CreateApplicationBuilder(args);
    builder.Services.AddScheduler();
    
    var host = builder.Build();
    
    host.Services.UseScheduler(s =>
    {
        s.Schedule(() => Console.WriteLine("It's alive! 🧟")).EverySecond();
    });
    
    host.Run();
  7. Setup Coravel Queuing

    master

    To use Coravel's in-memory queuing, register the service in your Startup.cs file within the ConfigureServices() method. You can then inject the Coravel.Queuing.Interfaces.IQueue interface into your classes (e.g., controllers) to access queuing functionality.

    // In Startup.cs
    services.AddQueue();
    
    // In your controller/class
    IQueue _queue;
    
    public HomeController(IQueue queue) {
        this._queue = queue;
    }
  8. Apply Day Constraints and Zoned Schedules

    master

    Day Constraints

    Restrict tasks to specific days by chaining day methods:

    • Monday(), Tuesday(), Wednesday(), Thursday(), Friday(), Saturday(), Sunday()
    • Weekday(), Weekend()
    • Example: .Monday().Wednesday() runs only on Mondays and Wednesdays.

    Zoned Schedules

    To run tasks against a specific time zone instead of UTC, use the Zoned() method with a TimeZoneInfo instance:

    scheduler
        .Schedule<SendWelcomeUserEmail>()
        .DailyAt(13, 30)
        .Zoned(TimeZoneInfo.Local);
  9. Schedule Invocables

    master

    Invocables are the recommended way to schedule tasks. To use them:

    1. Register your invocable class with the service provider as a scoped or transient service.
    2. Use the Schedule<T>() method to define the schedule.

    To handle graceful application shutdowns, make your long-running invocable classes implement Coravel.Invocable.ICancellableInvocable. You can then check the CancellationToken property (e.g., CancellationToken.IsCancellationRequested) within your logic.

    scheduler
        .Schedule<GrabDataFromApiAndPutInDBInvocable>()
        .EveryTenMinutes();
  10. Configure the Mailer in .NET

    master

    To enable the mailer in your application, call AddMailer() during service registration.

    For modern minimal APIs in Program.cs:

    var builder = WebApplication.CreateBuilder(args);
    builder.AddMailer();

    For non-web projects using Startup.ConfigureServices():

    services.AddMailer(this.Configuration); // Instance of IConfiguration
    var builder = WebApplication.CreateBuilder(args);
    
    builder.AddMailer();