2023-01-19 21:27:15 +00:00
|
|
|
# ch8-08-while-timer.rsc
|
|
|
|
|
|
|
|
# script to report page load time of google.com
|
|
|
|
|
|
|
|
# get the current time
|
|
|
|
:local CurrentTime [/system clock get time];
|
|
|
|
|
|
|
|
# calculate the time in 1 minute
|
|
|
|
:local EndTime ($CurrentTime + 00:01:00);
|
|
|
|
|
|
|
|
# define a target web site
|
|
|
|
:local WebSite "www.google.com";
|
|
|
|
|
2023-03-06 20:56:48 +00:00
|
|
|
# run a while loop until one minute interval has expired
|
2023-01-19 21:27:15 +00:00
|
|
|
:while ( [/system clock get time] < $EndTime ) do={
|
|
|
|
|
|
|
|
:put "Getting web page from $WebSite";
|
|
|
|
|
|
|
|
# fetch a page from web site
|
2023-03-06 20:56:48 +00:00
|
|
|
:local FetchResult;
|
|
|
|
:local TimeTaken [:time {
|
|
|
|
:set FetchResult [/tool fetch url=("https://$WebSite") \
|
|
|
|
mode=https http-method=get as-value keep-result=no];
|
|
|
|
}];
|
2023-01-19 21:27:15 +00:00
|
|
|
|
|
|
|
if ($FetchResult->"status" = "finished") do={
|
|
|
|
# print out how long page retrieval took (if successful)
|
2023-03-06 20:56:48 +00:00
|
|
|
:put "Web page fetch time: $TimeTaken secs";
|
2023-01-19 21:27:15 +00:00
|
|
|
} else={
|
2023-03-06 20:56:48 +00:00
|
|
|
# print failure message if fetch failed
|
2023-01-19 21:27:15 +00:00
|
|
|
:put "Web page fetch failed";
|
|
|
|
}
|
|
|
|
|
|
|
|
# pause for 5 seconds
|
|
|
|
:delay 5;
|
|
|
|
}
|
2023-03-06 20:56:48 +00:00
|
|
|
:put "One minute period has ended!"
|