IAMCronJob 1.0.1

dotnet add package IAMCronJob --version 1.0.1
                    
NuGet\Install-Package IAMCronJob -Version 1.0.1
                    
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="IAMCronJob" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IAMCronJob" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="IAMCronJob" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IAMCronJob --version 1.0.1
                    
#r "nuget: IAMCronJob, 1.0.1"
                    
#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.
#:package IAMCronJob@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IAMCronJob&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=IAMCronJob&version=1.0.1
                    
Install as a Cake Tool

IAMCronJob

IAMCronJob adalah background task scheduler yang ringan (lightweight) dan tanpa dependency pihak ketiga (Zero Dependency) untuk .NET & ASP.NET Core / Blazor.

Sistem ini dirancang dengan gaya pendaftaran sederhana ala Quartz.NET, menggunakan Native Cron Parser bawaan, serta mendukung eksekusi paralel antar-job sekaligus mencegah eksekusi ganda (anti-overlap) pada job yang sama.


✨ Fitur Utama

  • 🚀 Zero External Dependencies: Tidak membutuhkan library tambahan seperti Cronos, Quartz, atau Hangfire.
  • Parallel Execution: Job A dan Job B yang memiliki jadwal sama dapat berjalan secara independen tanpa saling mengunci.
  • 🛡️ Anti-Concurrent / Anti-Overlap: Jika Job A membutuhkan waktu eksekusi yang lebih lama dari interval Cron-nya, panggilan Job A berikutnya akan otomatis di-SKIP sampai eksekusi sebelumnya selesai.
  • 🔄 Safe Scoped Services: Masing-masing job dieksekusi dalam IServiceScope baru sehingga aman digunakan bersama DbContext (EF Core) tanpa resiko Memory Leak atau Object Disposed Exception.
  • 🌐 Multi-Platform Support: Kompatibel dengan .NET 6.0, 7.0, 8.0+, Blazor Server, Web API, Worker Service, maupun Console App.

📦 Instalasi

Install via NuGet Package Manager CLI:

dotnet add package IAMCronJob

Atau melalui Package Manager Console:

Install-Package IAMCronJob

🚀 Cara Penggunaan

1. Buat Class Job

Buat class yang mengimplementasikan interface IIAMJob. Anda bisa menggunakan Dependency Injection pada constructor-nya.

using IAMCronJob.Interfaces;
using Microsoft.Extensions.Logging;

public class ProcessAbsensiJob : IIAMJob
{
    private readonly ILogger<ProcessAbsensiJob> _logger;

    // Bebas lakukan inject service scoped seperti DbContext, dll.
    public ProcessAbsensiJob(ILogger<ProcessAbsensiJob> logger)
    {
        _logger = logger;
    }

    public async Task ExecuteAsync(CancellationToken cancellationToken)
    {
        _logger.LogInformation("Job Absensi dimulai...");
        
        // Simulasikan tugas async
        await Task.Delay(3000, cancellationToken);
        
        _logger.LogInformation("Job Absensi selesai.");
    }
}

2. Registrasikan Job di Program.cs

Gunakan extension method AddIAMCronJob<T> untuk mendaftarkan job dengan ekspresi Cron standar 5-part (Menit Jam HariBulan Bulan HariMinggu).

using IAMCronJob.Extensions;

var builder = WebApplication.CreateBuilder(args);

// =========================================================
// REGISTRASI IAMCronJob
// =========================================================

// Jalankan ProcessAbsensiJob setiap 1 menit
builder.Services.AddIAMCronJob<ProcessAbsensiJob>("* * * * *");

// Jalankan BackupDataJob setiap jam 12 malam
builder.Services.AddIAMCronJob<BackupDataJob>("0 0 * * *");

// Jalankan SynchronizeJob setiap 5 menit (Berjalan Paralel dengan Job lainnya)
builder.Services.AddIAMCronJob<SynchronizeJob>("*/5 * * * *");

var app = builder.Build();
app.Run();

📅 Panduan Format Cron Expression

Format Cron standar menggunakan 5 bagian:

*  *  *  *  *
│  │  │  │  └──────── Day of Week (0 - 6) (0 = Sunday)
│  │  │  └─────────── Month (1 - 12)
│  │  └────────────── Day of Month (1 - 31)
│  └───────────────── Hour (0 - 23)
└──────────────────── Minute (0 - 59)

Contoh Format:

Cron Expression Keterangan Eksekusi
* * * * * Dijalankan setiap menit
*/5 * * * * Dijalankan setiap 5 menit
0 * * * * Dijalankan setiap jam (menit ke-0)
0 8 * * * Dijalankan setiap hari jam 08:00 pagi
0 8 * * 1-5 Dijalankan jam 08:00 pagi, hanya hari Senin - Jumat
0 0 1 * * Dijalankan tanggal 1 setiap bulan jam 00:00
0 9,13,17 * * * Dijalankan jam 09:00, 13:00, dan 17:00

⚙️ Logika Anti-Overlap (Penting)

Jika suatu Job dikonfigurasi untuk berjalan setiap 1 menit (* * * * *), namun proses eksekusinya memakan waktu 3 menit:

  • Menit ke-1: Job berjalan dan memegang lock.
  • Menit ke-2: Jadwal memicu Job lagi. Karena Job pertama masih berjalan, eksekusi menit ke-2 akan di-SKIPPED (muncul warning di Log).
  • Menit ke-3: Eksekusi menit ke-3 juga akan di-SKIPPED jika Job pertama belum selesai.
  • Menit ke-4: Job pertama sudah selesai (lock dilepas). Eksekusi menit ke-4 akan berjalan normal kembali.

hal ini memastikan database atau server Anda tidak akan kehabisan resource akibat penumpukan tugas (task stacking).


📄 Lisensi

MIT License

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.1 106 8/19/2026
1.0.0 95 8/19/2026