How to implement a Cron task in Ada ?
The precision of the Cron task can be 1 second; sub-seconds are not necessary.
with Ada.Text_IO;
With Ada.Calendar;
With Ada.Calendar.Formatting;
use Ada.Text_IO;
use Ada.Calendar;
use Ada.Calendar.Formatting;
package body Cronjob is
procedure Run_Cron_Task is
task T;
task body T is
begin
loop
declare
Now:Time:=Ada.Calendar.Clock;
My_Hour:Hour_Number:=Ada.Calendar.Formatting.Hour(Now);
My_Minute:Minute_Number:=Ada.Calendar.Formatting.Minute(Now);
My_Second:Second_Number:=Ada.Calendar.Formatting.Second(Now);
begin
if My_Hour = 01 And My_Minute = 00 And My_Second = 01 then -- time 01:00:00
Put_Line("We are running Cronjob at Time");
Put_Line(Image(Now));
delay 1.0; -- extra delay ..make that the crone doesn't get triggered twice
end if;
delay 0.5; -- not sure about the delay here
end;
end loop;
end T;
begin
null;
end Run_Cron_Task;
end Cronjob;
Maybe somebody have an more elegant way how to implement that?