rejetto forum
Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Mars on January 27, 2009, 11:28:36 PM
-
Since some build, everybody heard about the file hfs.events.
Every event of hfs.events is predetermined with regard to certain sections of the main template hfs.tpl.
For more variety, I crossed quite a lot of time to study the subject and some small additions stood out from my imagination, and for reasons of compatibility with the sources of rejetto, I had to use names predefined for sections added in hfs.events.
The new type of section is [sym-event xxxxxxxxx] and is characterized by two versions:
[sym-event every xx] and [sym-event at xx]
It is obvious that these features will be completely operational in the next French version of silentpliz ;)
The used code is the following one:
.......
end; // calculateETA
procedure runTimeEvent(timer:integer); //add by mars
var
sym_events:TStringDynArray;
i:integer;
sym_eventname:string;
hourTime, everyTime:integer;
AtTime:TDateTime;
begin
sym_events:=eventScripts.getSyms();
if not Length(sym_events)>0 then exit;
for i:= 0 to Length(sym_events)- 1 do
begin
sym_eventname:=sym_events[ i ];
chop('sym-event',sym_eventname);
sym_eventname:=lowercase(trim(sym_eventname));
// [sym-event every 1:04] or [sym-event every 64] = event every 64 minutes
if ansiStartsStr('every',sym_eventname) then
begin
chop('every',sym_eventname);
trim(sym_eventname);
hourtime:=0;
try
if pos(':',sym_eventname) >0 then
hourTime:=strtoint(chop(':',sym_eventname));
everyTime:=strtoint(sym_eventname);
except continue; end;
everyTime:= hourTime*60+everyTime;
if (everyTime > 0) and ((timer mod everyTime)= 0) then
runEventScript(sym_events[ i ]);
continue;
end;
// [sym-event at 3PM] or [sym-event at 15:00] or [sym-event at 15] = event at 15h00
if ansiStartsStr('at',sym_eventname) then
begin
chop('at',sym_eventname);
try atTime:=strtotime(trim(sym_eventname))
except continue; end;
if (AnsiLeftStr(TimeToStr(atTime),5) = AnsiLeftStr(TimeToStr(Time),5)) then
runEventScript(sym_events[ i ]);
continue;
end;
end; //next i
end; //RunTimeEvent
procedure updateEventScripts();
...........
..........
procedure everyMinute();
begin
if quitting then exit;
runTimeEvent(clock div (60*10)); //add by mars : time events
if updateDailyChk.Checked then
autoCheckUpdates();
// purge icons older than 5 minutes, because sometimes icons change
iconsCache.purge(now_-(5*60)/SECONDS);
end; // everyMinute
:o I was going to forget to join the part adding to the file hfs.events in example.
[sym-event every 1]
{.add to log|this section is called every 1 minutes.}
[sym-event every 3]
{.add to log|this section is called every 3 minutes.}
[sym-event every 5]
{.add to log|this section is called every 5 minutes.}
[sym-event every 1:4]
{.add to log|this section is called every 64 minutes.}
[sym-event every 2]
{.add to log|this section is called every 2 minutes.}
[sym-event every 25]
{.add to log|this section is called every 25 minutes.}
[sym-event every 60]
{.add to log|this section is called every 1 hour.}
[sym-event every 1440]
{.add to log|this section is called every 1 day.}
[sym-event at 23:18]
{.add to log|this section is called at 23:18.}
[sym-event at 23:16]
{.add to log|this section is called at 23:16.}
[sym-event at 11PM]
{.add to log|this section is called at 23h00.}
topic locked, because to be continue...
-
yes, i like it, i was thinking something like that the other day.
1. i don't think sym-event is a good name. Is borrowed from the old user %symbols% thing. It has actually nothing to do with symbols and is very obscure for the users. I guess [every XXX] should be enough, we'd check for "every " (with space), and it will hardly clash with anything else. OK?
2. I think seconds should be allowed for the 'every'. We may have a default unit and let the user specify other, like [every 3 hours] or [every 3 h], and [every 4 minutes] or [every 4 m].
what you think would it be the best default unit? minutes or seconds?
-
what you think would it be the best default unit? minutes or seconds?
Inasmuch as we have seen (mars and me), a gap between the call and run the macro (between 5 seconds and 30 seconds), perhaps the unit defaults in seconds would be an best solution.
-
1. i don't think sym-event is a good name.
Sym-event is the only possibility that I was able to use without modifying one so much is little the sources of hfs, indeed if you look of the highly-rated of the type Ttpl, several elements are missing:
Ttpl = class
....
public
function getsections():TStringDynArray; //as getsyms()
function getSectionByID(id:integer):string;
var count:integer
OK for the renunciation of the part 'sym-', but it is necessary to keep the 'event' word in the name of section.
For me it will be this syntax, there will be no bargaining ;D ;D
[event every xx:xx]
[event at xx:xx]
what you think would it be the best default unit? minutes or seconds?
Concerning the unit of measure, it is possible to shorten the imposed delai of 1 minute, but it is necessary to think that too much of moved closer events could create an overload of hfs, and thus damage the system, as for the used syntax xx:xx, it is in compliance with the type Ttime
To use a timming below 30 seconds would be absurd, because we can already notice a delay of approximately 37 seconds between the passage of the clock system in the next minute and the beginning of the concerned event
It is in noted that the event [event every xx:yy] runs quite xx hours+ yy minutes which follow the starting up of hfs, the event [event at yy:yy] runs at the indicated hour incremented of at least 30 seconds.
I am going to work on a version of 'event at' which will begin in the chosen minute and about is the hour, by example xx:35, every new hour + 35 minutes (+30 seconds :D)
-
OK for the renunciation of the part 'sym-', but it is necessary to keep the 'event' word in the name of section.
For me it will be this syntax, there will be no bargaining ;D ;D
[event every xx:xx]
[event at xx:xx]
mmmm, i meant to remove also "event" because in the events file, anything in [square brackets] is an event.
it would be like naming a variable to keep the age of a person "variableAge". :)
To use a timming below 30 seconds would be absurd, because we can already notice a delay of approximately 37 seconds between the passage of the clock system in the next minute and the beginning of the concerned event
it's because you put the handling inside everyMinute()
I am going to work on a version of 'event at' which will begin in the chosen minute and about is the hour, by example xx:35, every new hour + 35 minutes (+30 seconds :D)
like "cron" :)
did you do it then?
i'm not sure this is the good way to go.
maybe something similar to javascript setTimer() will give us more power with less coding.
-
aaaaaaaaaaaaaaaah
finally i found why you insisted on the "sym" thing.
there was a legacy handling for sections with that name. (the getSyms)
that function is not used anymore, since the new macro system can work without it.
and since the name "sym" is very ugly, i think i will shortly remove it.
i think it is better that we just make "sections" array to be public.
like...
for i:=0 to length(eventScripts.sections)-1 do
with eventScripts.sections[i] do
if ansiStartsText('every ', name) then
-
Of course! Dear Sherlock Holmes ;D
-
i think it is better that we just make "sections" array to be public.
like...
for i:=0 to length(eventScripts.sections)-1 do
with eventScripts.sections[i] do
if ansiStartsText('every ', name) then
i'm trying this solution, but i fear it is not good.
it is not compatible with the "diff template" technology (the "over" thing).
i know we are not using this for event scripts yet, but i suspect we may in the future.
so, my new suggestion is to have a getSections() that will return all section' names.
-
ok, i finally found my way through this.
next build will have [every XXX] and [at HH:MM]
XXX is in seconds, but you can use minutes or hours. examples
[every 5] (that is 5 seconds)
[every 3 hours]
[every 4h]
[every 15 minutes]
[every 1.5m] (that is 90 seconds)
[every 1:15 min] (that is 75 minutes)
HH:MM is instead in standard 24 hours format, but you can do things like
[at 0:00=at 6:00=at 12:00=at 18:00]
this will trigger every six hours, but at specific times.
while [every 6 hours] would trigger at same intervals but differently placed in time.
-
So in the matter of the schedule set ini I can simply create a section called [at 18:00] and the command under it? If so this is very nice.
-
exactly
-
Does not work, at least for me.
-
build 232
hfs.events
[every 10]
{.add to log|KREMLIN.}
-
I'm refering to the [at 18:00]
Tryed it with the set ini command and it didn't trigger even with a download start. This must be a set ini macro problem because other commands seem to work with these macros
-
can you give us your hfs.events to see where is the pb (MP if you prefer)
-
By hfs.events I suppose you meen the log that show in HFS (requests, download completed, etc..). If so that's just it, nothing shows about the set ini command, not like when I do it via http with a button option. If not then please explain how to get the hfs.events file.
-
into the same folder as hfs.exe you have hfs.tpl the current template, you can modify it from hfs by using the key F6, to modify or create the file hfs.events, use the same way by usint keys: ALT+F6
in it put the section
[every 10]
{.add to log|KREMLIN.}
then every ten seconds the word KREMLIN appear in hfs log-box
all posts about events reffer them to the file hfs.events
-
Ok, so I've actually tested something, opened threw ALT+F6 the hfs.events and added the commands that were previously in the template file (that didn't trigger the set ini command), and now it works.
these were the commands:
[at 21:45]
{.set ini|speed-limit=100.}
[at 21:46]
{.set ini|speed-limit=-1.}
So why does it work in hfs.events and not in the template file?
PS. my hfs.events was clean before i added these commands.
-
sections in template hfs.tpl are running only when a user is connected on the server and refresh his browser.
events (sections) in hfs.events are working when some sections are visited in hfs.tpl, but since some older build some events are associate with hfs.exe comportement [start] [quit] [upload-name] [archive-name] [download-name] .....
some bugs are not resolved with [upload completed] and [download completed] with build 232,
build 232 give events with every xx or at xx times
-
At least now we know what was happening, anyway posted the tutorial for the schedule set ini in it's proper topic.
-
template and events are something totally separated.
they are used for different things.
they just share the syntax.
the whole "events" system is not documented yet, not only the scheduling.
-
Summary on events here
http://www.rejetto.com/forum/index.php?topic=6845.0