:-eval(consult('ContractLog/math.prova')).
:-eval(consult('ContractLog/list.prova')).
:-eval(consult('ContractLog/list_math.prova')).
:-eval(consult('ContractLog/datetime.prova')).
:-eval(consult('ContractLog/timeinterval.prova')).
:-eval(consult('ContractLog/ecaruntime.prova')).



% ECA rules which call external waiter method
% Fire rule 1 every 10 seconds and wait for 5 seconds
eca(every10Sec(DT,1), rbsla.utils.WebsiteAvailable.waiter(5),_,ok(DT,1),_,negok(1)).
% Fire rule 2 every 2 seconds and wait for 2 seconds
eca(every2Sec(DT,2), rbsla.utils.WebsiteAvailable.waiter(2),_,ok(DT,2),_,negok(2)).
% Fire rule 3 every 5 seconds and wait for 5 seconds
eca(every5Sec(DT,3), rbsla.utils.WebsiteAvailable.waiter(5),_,ok(DT,3),_,negok(3)).

%TIME
every10Sec(DT,Y) :-
	sysTime(DT),
	interval(timespan(0,0,0,10), DT),
	println(["Start rule ",Y]).
	
every2Sec(DT,Y) :-
	sysTime(DT),
	interval(timespan(0,0,0,2), DT),
		println(["Start rule ",Y]).

every5Sec(DT,Y) :-
	sysTime(DT),
	interval(timespan(0,0,0,5), DT),
		println(["Start rule ",Y]).

%%---------------------- ACTION OF THE ECA -------------------------------


ok(DT,X) :- 
	sysTime(DTNEW),
	println(["Started at ",DT," fired rule ",X," at ",DTNEW]).

negok(X) :- println(["failed rule ",X]).

%---------------------- CONDITION OF THE ECA ------------------------------



	
%-----------------------------------------------------------------------
% Start the ECA runtime
%-----------------------------------------------------------------------

start():-
	startECARuntimeMultiThreading(".\examples\function_tests\eca_runtime\ecaMultiThreading.prova").
	
:- solve(start()).
		
