Skip to content

Commit 4032bf0

Browse files
committed
Add a one-shot mode
Now that we store our "state" on disk, we lose nothing by exiting and restarting every time. In return, we gain the ability to schedule with a supervisor like systemd.
1 parent bf7c4c3 commit 4032bf0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

app/Main.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ data Options = Options
139139
, oLocalPath :: Maybe FilePath -- default $HOME
140140
, oGithubAccount :: String -- default "commercialhaskell"
141141
, oDelay :: Maybe Int -- default 60 seconds
142+
, oOneShot :: Bool
142143
, oS3Bucket :: Maybe BucketName
143144
, oAwsDiscoveryMech :: AwsDiscoverMechanism
144145
}
@@ -187,6 +188,10 @@ optionsParser =
187188
help
188189
("Delay in seconds before next check for a new version " ++
189190
"of 01-index.tar.gz file")))) <*>
191+
(switch
192+
(long "one-shot" <>
193+
help
194+
("Update once and exit, instead of polling forever. "))) <*>
190195
(optional
191196
((BucketName . pack) <$>
192197
(strOption
@@ -222,7 +227,7 @@ main = do
222227
"WARNING: No s3-bucket is provided. Uploading of 00-index.tar.gz will be disabled."
223228
reposInfoInit <- getReposInfo localPath oGithubAccount gitUser
224229
withHackage (localPath </> "hackage-security-cache") $ \hackage -> do
225-
let innerLoop reposInfo forceUpdate = do
230+
let onePass reposInfo forceUpdate = do
226231
putStrLn "Checking index"
227232
now <- getCurrentTime
228233
commitMessage <- getCommitMessage
@@ -234,6 +239,9 @@ main = do
234239
Just s3Bucket ->
235240
updateIndex00 oAwsDiscoveryMech s3Bucket
236241
_ -> return ()
242+
return newInfo
243+
let innerLoop reposInfo forceUpdate = do
244+
newInfo <- onePass reposInfo forceUpdate
237245
threadDelay delay
238246
innerLoop newInfo False
239247
let outerLoop = do
@@ -247,4 +255,6 @@ main = do
247255
show e
248256
threadDelay delay
249257
outerLoop)
250-
outerLoop
258+
if oOneShot
259+
then void $ onePass reposInfoInit False
260+
else outerLoop

0 commit comments

Comments
 (0)