Commit a8fe98bc authored by Klaus Aehlig's avatar Klaus Aehlig

Factor out function to delay a thread in seconds

...thus avoiding the magic constants 1000000 (number of microseconds in a
second) all over the place.
Signed-off-by: 's avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: 's avatarPetr Pudlak <pudlak@google.com>
parent 65c75276
......@@ -82,7 +82,7 @@ query client crType cQuery = do
hmac = hmacKey client
jobs = map (queryOneServer semaphore answer crType cQuery hmac) dest
watchdog reqAnswers = do
threadDelay $ 1000000 * C.confdClientExpireTimeout
threadDelaySeconds C.confdClientExpireTimeout
_ <- swapMVar reqAnswers 0
putMVar semaphore ()
waitForResult reqAnswers = do
......
......@@ -121,10 +121,6 @@ onQueuedJobs = over qEnqueuedL
unreadJob :: QueuedJob -> JobWithStat
unreadJob job = JobWithStat {jJob=job, jStat=nullFStat, jINotify=Nothing}
-- | Reload interval for polling the running jobs for updates in microseconds.
watchInterval :: Int
watchInterval = C.luxidJobqueuePollInterval * 1000000
-- | Read a cluster parameter from the configuration, using a default if the
-- configuration is not available.
getConfigValue :: (Cluster -> a) -> a -> JQStatus -> IO a
......@@ -488,7 +484,7 @@ updateStatusAndScheduleSomeJobs qstate = do
-- | Time-based watcher for updating the job queue.
onTimeWatcher :: JQStatus -> IO ()
onTimeWatcher qstate = forever $ do
threadDelay watchInterval
threadDelaySeconds C.luxidJobqueuePollInterval
logDebug "Job queue watcher timer fired"
updateStatusAndScheduleSomeJobs qstate
logDebug "Job queue watcher cycle finished"
......
......@@ -96,6 +96,7 @@ module Ganeti.Utils
, ensurePermissions
, ordNub
, isSubsequenceOf
, threadDelaySeconds
) where
import Control.Applicative
......@@ -189,6 +190,10 @@ ensureQuoted v = if not (all (\c -> isAlphaNum c || c == '.') v)
then '\'':v ++ "'"
else v
-- | Delay a thread for several seconds.
threadDelaySeconds :: Int -> IO ()
threadDelaySeconds = threadDelay . (*) 1000000
-- * Mathematical functions
-- Simple and slow statistical functions, please replace with better
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment