Improve jobhandling
This commit is contained in:
parent
0b4afaf9ee
commit
d257535ee8
2 changed files with 17 additions and 8 deletions
|
@ -22,6 +22,9 @@ in {
|
||||||
imports = [ ./kassandra.nix ./test-config.nix ];
|
imports = [ ./kassandra.nix ./test-config.nix ];
|
||||||
config = {
|
config = {
|
||||||
services.laminar.cfgFiles = {
|
services.laminar.cfgFiles = {
|
||||||
|
env = builtins.toFile "laminar-env" ''
|
||||||
|
TIMEOUT=14400
|
||||||
|
'';
|
||||||
scripts = {
|
scripts = {
|
||||||
"nix-jobs" = pkgs.writeHaskell "nix-jobs" {
|
"nix-jobs" = pkgs.writeHaskell "nix-jobs" {
|
||||||
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
|
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
|
||||||
|
|
|
@ -114,11 +114,17 @@ runningPath p = [i|#{runningDir}/#{drvBasename p}|]
|
||||||
resultPath p = [i|#{resultDir}/#{drvBasename p}|]
|
resultPath p = [i|#{resultDir}/#{drvBasename p}|]
|
||||||
|
|
||||||
-- Bool means derivation itself needs to be build
|
-- Bool means derivation itself needs to be build
|
||||||
getDependenciesFromNix :: Text -> IO (Seq Text, Bool)
|
getDependenciesFromNix :: Text -> IO (Seq Text)
|
||||||
getDependenciesFromNix derivationName = do
|
getDependenciesFromNix derivationName = do
|
||||||
|
everythingToDo <- nixStoreRealiseDryRun derivationName
|
||||||
|
pure $ Seq.filter (/= derivationName) everythingToDo
|
||||||
|
|
||||||
|
-- Bool means derivation itself needs to be build
|
||||||
|
needsBuild :: Text -> IO Bool
|
||||||
|
needsBuild derivationName = do
|
||||||
everythingToDo <- nixStoreRealiseDryRun derivationName
|
everythingToDo <- nixStoreRealiseDryRun derivationName
|
||||||
let depsToDo = Seq.filter (/= derivationName) everythingToDo
|
let depsToDo = Seq.filter (/= derivationName) everythingToDo
|
||||||
pure (depsToDo, everythingToDo /= depsToDo)
|
pure (everythingToDo /= depsToDo)
|
||||||
|
|
||||||
nixStoreRealiseDryRun :: Text -> IO (Seq Text)
|
nixStoreRealiseDryRun :: Text -> IO (Seq Text)
|
||||||
nixStoreRealiseDryRun derivationName = do
|
nixStoreRealiseDryRun derivationName = do
|
||||||
|
@ -148,8 +154,8 @@ job derivationName = do
|
||||||
createDirectoryIfMissing True resultDir
|
createDirectoryIfMissing True resultDir
|
||||||
writeFileText (resultPath derivationName) (show result)
|
writeFileText (resultPath derivationName) (show result)
|
||||||
removeFile (runningPath derivationName)
|
removeFile (runningPath derivationName)
|
||||||
needBuild <- ensureDeps Children derivationName
|
ensureDeps Children derivationName
|
||||||
unless needBuild $ do
|
unlessM (needsBuild derivationName) $ do
|
||||||
setResult Success
|
setResult Success
|
||||||
say [i|Build for #{derivationName} had already happened.|]
|
say [i|Build for #{derivationName} had already happened.|]
|
||||||
exitSuccess
|
exitSuccess
|
||||||
|
@ -167,14 +173,13 @@ job derivationName = do
|
||||||
nixStoreRealise :: Text -> [Text] -> IO ()
|
nixStoreRealise :: Text -> [Text] -> IO ()
|
||||||
nixStoreRealise name flags = nix_store (["-r", name] <> flags)
|
nixStoreRealise name flags = nix_store (["-r", name] <> flags)
|
||||||
|
|
||||||
ensureDeps :: ReportLevel -> Text -> IO Bool
|
ensureDeps :: ReportLevel -> Text -> IO ()
|
||||||
ensureDeps level derivationName = do
|
ensureDeps level derivationName = do
|
||||||
(dependencies, needBuild) <- getDependenciesFromNix derivationName
|
dependencies <- getDependenciesFromNix derivationName
|
||||||
whenChildren level $ forM_ dependencies $ \dep -> say [i|Requiring #{dep}.|]
|
whenChildren level $ forM_ dependencies $ \dep -> say [i|Requiring #{dep}.|]
|
||||||
forConcurrently_ dependencies (realise $ levelPrec level)
|
forConcurrently_ dependencies (realise $ levelPrec level)
|
||||||
`catch` \(JobException e) ->
|
`catch` \(JobException e) ->
|
||||||
throw [i|#{e}\nFailed dependency for #{derivationName}|]
|
throw [i|#{e}\nFailed dependency for #{derivationName}|]
|
||||||
pure needBuild
|
|
||||||
|
|
||||||
-- Nothing means failing to acquire lock on the derivation name for starting the job.
|
-- Nothing means failing to acquire lock on the derivation name for starting the job.
|
||||||
tryQueue :: Text -> IO (Maybe Text)
|
tryQueue :: Text -> IO (Maybe Text)
|
||||||
|
@ -234,7 +239,8 @@ getRunningJob derivationName = poll 0
|
||||||
|
|
||||||
realise :: ReportLevel -> Text -> IO ()
|
realise :: ReportLevel -> Text -> IO ()
|
||||||
realise level derivationName = do
|
realise level derivationName = do
|
||||||
needBuild <- ensureDeps level derivationName
|
ensureDeps level derivationName
|
||||||
|
needBuild <- needsBuild derivationName
|
||||||
if needBuild
|
if needBuild
|
||||||
then runBuild
|
then runBuild
|
||||||
else whenSelf level $ say [i|#{derivationName} was already built.|]
|
else whenSelf level $ say [i|#{derivationName} was already built.|]
|
||||||
|
|
Loading…
Reference in a new issue