maxCRON – lightweight CRON scheduler for Delphi

Flexible, lightweight CRON compliant scheduler written in Delphi. Works directly from the code.

Main features:

Sample scheduler usage:

procedure TForm1.FormCreate(Sender: TObject);
var
  NewSchedule: TScheduleEvent;
begin 
  
  // create new TChronScheduler that will hold events
  ChronScheduler := TmaxCron.Create;
  
  // first event
  NewSchedule := ChronScheduler.Add('Event1', '1 * * * * *', OnScheduleEvent1).Run;
  
  // second event
  NewSchedule := ChronScheduler.Add('Event2', '1 * * * * *', OnScheduleEvent2).Run;
  
  // third event
  NewSchedule := ChronScheduler.Add('Event3', '1 * * * * *', OnScheduleEvent3).Run; 

  // you can use anonymous methods as well
  NewSchedule := ChronScheduler.Add('Event2');
  NewSchedule.EventPlan := '*/2 * * * * *';
  NewSchedule.OnScheduleproc := procedure(aEvent: TmaxCronEvent)
    begin
      OnScheduleTrigger(aEvent);
    end;
  NewSchedule.Run;
  
  
  // using a shorter adding syntax
  NewSchedule := ChronScheduler.Add('Event4', '1 * * * * *',
    procedure(aEvent: TmaxCronEvent)
    begin
      OnScheduleTrigger(aEvent);
    end).Run;
end;

using the TCronSchedulePlan:

The TPlan is a small class that allows you to specify the parts in a more friendly way and then convert them to a cron string

  plan := TCronSchedulePlan .create;
  // you can use the clear  method to reset all the values to their defaults like this:
  plan.Clear;
  // you can access any of the fields just like that:
  plan.Second := '30';
  // now create a new event using our new plan
  NewSchedule := ChronScheduler.Add('EventFromTPlan', plan.text, OnScheduleTrigger).Run;

Example how to use From / To valid range. The event will fire for one year, every sunday, every second hour, but only on 1,5 and 10 month in the year.


  // start time is in 50 seconds
  startDate := now() + 1 / 24 / 60 / 60 * 50;
  // and stop 5 minutes afterwards
  StopDate := startDate + 1 / 24 / 60 * 5;
  log('Ranged Event start date: ' + showDate(startDate));
  log('Ranged Event stop date: ' + showDate(StopDate));
  NewSchedule := ChronScheduler.Add('RangedSchedule');
  NewSchedule.EventPlan := '0 0 */2 * 1,5,10 7 *';
  NewSchedule.OnScheduleEvent := OnScheduleTrigger;
  NewSchedule.ValidFrom := startDate;
  NewSchedule.ValidTo := StopDate;
  NewSchedule.Run;

If you have trouble using the code or have any other questions, please contact me directly using the “Contact” page.

[wpfilebase tag=file path=”delphi/maxCron.zip”]