I have small program that need to be executed every 5 minutes.
For now, I have shell script that perform that task, but I want to provide for user ability to run it without additional scripts via key in CLI.
What is the best way to achieve this?
I have small program that need to be executed every 5 minutes.
For now, I have shell script that perform that task, but I want to provide for user ability to run it without additional scripts via key in CLI.
What is the best way to achieve this?
I presume you'll want something like that (more or less pseudocode):
import Control.Concurrent (forkIO, threadDelay)
import Data.IORef
import Control.Monad (forever)
main = do
var <- newIORef 5000
forkIO (forever $ process var)
forever $ readInput var
process var = do
doActualProcessing
interval <- readIORef var
_ <- threadDelay interval
readInput var = do
newInterval <- readLn
writeIORef var newInterval
If you need to pass some more complex data from the input thread to the processing thread, MVar
s or TVar
s could be a better choice than IORef
s.
forever
–
Mooneye process var
at the end of process
would make it infinitely recursive (thus looped) as well. –
Reformation TVar
s instead of, say, IORef
s ? Is there some atomicity issue in the code above? –
Lepidosiren IORef
s, but of course the code shown has no possible races. I'll edit it. –
Reformation IORef
or a TVar
at all. Just pass 5000
to process directly, –
Juncture © 2022 - 2024 — McMap. All rights reserved.
while(1) ...
– Mooneye./app -e -t 5
,e
key for endless run,t
- time interval – Mooneye