cancel
Showing results for 
Search instead for 
Did you mean: 

How to set timer and let q run automatically

kc3031
New Contributor
Hello,

I am trying to run a script that contains two function.

For function 1, I only need to run once a day; for function 2, I hope I can run every 10 minutes.

Can anyone guide me how to set up a timer and make it?

Many thanks in advance!

Best,
Kelly
2 REPLIES 2

AquaQMatt
New Contributor
Hi Kelly, 

Personally If I had a 1 day q script to run, i'd set this up to be run from crontab, both function could be set up using this but they would need to be in two separate scripts.
https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/


If it were solely to be using the Q timer function, something like this might work, using a counter to keep track - but it is likely not the most elegant solution.

//Perform function 1 every 600000ms (10 minutes) - Once idx hits 144 (1440 minutes per day, 10 min slices), run function 2. In my example the function is simply a print statement.
//Testcase ran every second, and function 2 every 8 seconds. (idx=0; if idx=8[...function 2])

q).z.ts:{show "F1: Performing Function 1";idx+:1;if[idx=144;show "F2: Performing Function 2";idx::0]}
q)\t 600000
q)"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F2: Performing Function 2"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F1: Performing Function 1"
"F2: Performing Function 2"


Hope this helps.
Kind regards,
Matt

Hi Matt,

Your solution really helps solve my problem! Thanks a lot for your help. 🙂

Best,
Kelly