Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions code/processes/reporter.q
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ queryid:`long$0; / - initial query id value
inputcsv:string inputcsv

/- stores report information
reports:([] name:`$(); query:(); resulthandler:(); gateway:(); joinfunction:(); proctype:(); procname:(); start:`minute$(); end:`minute$(); period:`minute$(); timeoutinterval:`timespan$(); daysofweek:());
reports:([] name:`$(); query:(); resulthandler:(); gateway:(); joinfunction:(); proctype:(); procname:(); start:`minute$(); end:`minute$(); period:`minute$(); timeoutinterval:`timespan$(); daysofweek:(); timezone:`$());

/- status of current queries
querystatus:([queryid:`u#`long$()] name:`symbol$(); time:`timestamp$(); servertype:(); timeout:`timespan$(); submittime:`timestamp$(); returntime:`timestamp$(); status:`boolean$(); stage:`$());
Expand Down Expand Up @@ -37,15 +37,15 @@ wrapper:{[name;query;qid]
csvloader:{[CSV]

/- rethrows error if file doesn't exist, checks to see if correct columns exist in file
t:@[{write[`long$0;"Opening ",x;0b];("s**s*Ssuuun*";enlist "|") 0: hsym `$x};CSV;{.lg.e[`csvloader;e:"failed to open ",x," : ",y];'e}[CSV]];
t:@[{write[`long$0;"Opening ",x;0b];("s**s*Ssuuun*s";enlist "|") 0: hsym `$x};CSV;{.lg.e[`csvloader;e:"failed to open ",x," : ",y];'e}[CSV]];

/- Replace Nested list string with actual nested list
t:update daysofweek:value each daysofweek, query:raze each query, proctype:raze each `$" " vs' string proctype from t;
/ check if the reporter.csv file matches the global table reports
$[not all (cols reports) in cols t;
'"The file (",CSV,") has incorrect layout";
/ - check if there are any null values or empty strings in required columns
any (not count each raze value exec query,resulthandler from t),null raze/[value flip delete query,resulthandler,joinfunction,gateway,procname from t];
any (not count each raze value exec query,resulthandler from t),null raze/[value flip delete query,resulthandler,joinfunction,gateway,procname,timezone from t];
'"File not loaded, null values were found in the csv file";
/ - cannot query against more than one processes when server is not a gateway process
any 1<count each exec proctype from t where null gateway;
Expand All @@ -64,9 +64,9 @@ datecheck:{

/- returns next nearest period timestamp, if period is 00:00:00 it will return start time and only runs once.
nextperiod:{[start;end;period;curr]
`timestamp$ .proc.cd[] + $[0i=`int$period;
$[0i=`int$period;
start;
first d where (d:s + sums 0,(`int$((`time$end)-s:`time$start)%p)#p:`time$period) >= `time$curr]}
first d where (d:start + sums 0,(`int$((`time$end)-s:`time$start)%p)#p:`time$period) >= `time$curr]}

/- checks if any queries have timed out
checktimeout:{
Expand Down Expand Up @@ -115,10 +115,13 @@ runreport:{[tab]
.timer.once[startts;fp;"Reporter - ",string tab`name];
`..timerids upsert 1!select id,periodend:nextrun from .timer.timer where fp~/:funcparam;
:()];
/ - if the current time is within the start and end timestamps, use current time as start time, else use the startts
/ - if timezone is specified convert the start and end timestamps to the time used by the system
startts:?[not null tab[`timezone];.tz.ttz[`GMT;tab[`timezone];$[.proc.localtime;gtime[startts];startts]];startts];
endts:?[not null tab[`timezone];.tz.ttz[`GMT;tab[`timezone];$[.proc.localtime;gtime[endts];endts]];endts];
/ - if the current time is within the start and end timestamps, use current time as start time, else use the startts
/ - work out the start time for the timer. For example a report could run every day from 10am to 6pm every 5 mins, if the reporter
/ - is started at 1:11pm, we need to know that the report should start 1:15pm and then run every 5 mins there after
startts: nextperiod[tab`start;tab`end;tab`period;] $[.proc.cp[] within startts,endts;.proc.cp[];startts];
startts: nextperiod[startts;endts;tab`period;] $[.proc.cp[] within startts,endts;.proc.cp[];startts];
/ - escape if the report havs already been registered on the timer
if[count select from .timer.timer where fp~/:funcparam;:()];
/ - register the report on the timer
Expand Down
2 changes: 1 addition & 1 deletion config/reporter.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
name|query|resulthandler|gateway|joinfunction|proctype|procname|start|end|period|timeoutinterval|daysofweek
name|query|resulthandler|gateway|joinfunction|proctype|procname|start|end|period|timeoutinterval|daysofweek|timezone