003 Leaner Low Risk Plan

# βœ… Lean Windows Task Scheduler Migration – Overall Approach

## 🎯 Core Principle

πŸ‘‰ **Do NOT redesign your scheduler framework**

πŸ‘‰ **Do NOT centralize into new orchestration services (yet)**

Instead:

Replace Coravel’s trigger mechanism with HTTP triggers

Keep your existing job logic almost unchanged


# 🧩 New Architecture (minimal change)

### BEFORE


Coravel Engine

   ↓

TaskSchedulerInitializer

   ↓

IInvocable schedulers

   ↓

Business logic

### AFTER


Windows Task Scheduler

   ↓ (HTTPS + API Key)

Thin API Endpoints

   ↓

Existing scheduler logic (slightly renamed)

   ↓

Business logic

# βœ… What stays the same

βœ” Your multi-database loops

βœ” Logging system

βœ” Email/report generation

βœ” Error handling

βœ” Business repositories

βœ” AI Insights flow


# ❌ What goes away

❌ Coravel packages

❌ IInvocable interface

❌ TaskSchedulerInitializer

❌ CRON-based runtime scheduling


# βœ… What gets added (very small)

βœ” One controller with endpoints

βœ” Minor refactor of scheduler classes to normal service/job classes

βœ” Windows Task Scheduler jobs


# πŸ“ Target structure (simple)


Api/

 β”œβ”€ Controllers/

 β”‚   └─ ScheduledJobsController.cs

 β”œβ”€ Jobs/

 β”‚   β”œβ”€ IndentEmailJob.cs

 β”‚   β”œβ”€ InvoiceEmailJob.cs

 β”‚   β”œβ”€ SalesOrderEmailJob.cs

 β”‚   └─ ...

# πŸ” Refactor pattern (key concept)

### OLD (Coravel)


public class InvoiceEmailScheduler : IInvocable

{

    public async Task Invoke()

    {

        foreach (var db in dbList)

        {

            // existing logic

        }

    }

}

### NEW (Lean)


public class InvoiceEmailJob

{

    public async Task Run(string dbName)

    {

        // SAME logic (almost copy-paste)

    }



    public async Task RunAll()

    {

        foreach (var db in dbList)

        {

            await Run(db);

        }

    }

}

# 🌐 API Trigger (thin layer)


\[ApiController]

\[Route("api/jobs")]

\[ApiKeyAuth]

public class ScheduledJobsController : ControllerBase

{

    \[HttpPost("invoice-email")]

&nbsp;   public async Task<IActionResult> RunInvoiceEmails()

&nbsp;   {

&nbsp;       await \_invoiceJob.RunAll();

&nbsp;       return Ok();

&nbsp;   }



&nbsp;   \[HttpPost("invoice-email/{dbName}")]

&nbsp;   public async Task<IActionResult> RunInvoiceForDb(string dbName)

&nbsp;   {

&nbsp;       await \_invoiceJob.Run(dbName);

&nbsp;       return Ok();

&nbsp;   }

}

# ⏰ Windows Task Scheduler

Each job:

Action β†’ HTTPS call:


POST https://yourapi/api/jobs/invoice-email?key=XXXX

Trigger β†’ daily/time as required


# πŸ” Security

βœ” HTTPS only

βœ” API key (already in place)

βœ” Optional IP restriction (later)


# πŸ“ˆ Logging

Keep existing logs.

Optionally add:


Job triggered from Windows Scheduler at {time}

# πŸ§ͺ Migration Strategy (safe)

### Step 1

Add API endpoints + job classes

### Step 2

Wire Windows Task Scheduler

### Step 3

Run both (Coravel OFF but code intact)

### Step 4

Verify few days

### Step 5

Remove Coravel packages


### πŸ‘‰ Instructions

Revise the Windows Task Scheduler migration plan to a lean approach:

* Do NOT introduce orchestration frameworks or new execution services

* Keep existing scheduler logic intact (just refactor out of Coravel IInvocable)

* Add thin HTTP API endpoints to trigger each job

* Use Windows Task Scheduler to call HTTPS endpoints with API key

* Remove Coravel dependencies only after validation

Show:

* Exact code changes for one or two scheduler classes as examples

* New controller code

* Program.cs changes

* Windows Task Scheduler trigger examples

Keep design minimal and low-risk.