Skip to content

Commit

Permalink
ENH Write out log to .failed files
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Sep 5, 2022
1 parent 8310bde commit 0fa54db
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased
* Add `names()` method to readset
* Add ``println()`` function
* Make ``print()`` accept ints and doubles as well as strings
* Write log to .failed files when using the parallel module

Version 1.4.2 2022-07-21 by luispedro
* Fix bug with parsing GFF files
Expand Down
14 changes: 13 additions & 1 deletion NGLess/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ module Output
, outputMappedSetStatistics
, writeOutputJS
, writeOutputTSV
, writeOutputTo
, outputConfiguration
) where

import Text.Printf (printf)
import System.IO (hPutStrLn, hIsTerminalDevice, stdout, stderr)
import System.IO (hPutStrLn, hIsTerminalDevice, stdout, stderr, Handle)
import System.IO.Unsafe (unsafePerformIO)
import System.IO.SafeWrite (withOutputFile)
import Data.Maybe (maybeToList, fromMaybe, isJust)
Expand Down Expand Up @@ -292,6 +293,17 @@ wrapScript script tags stats = first annotate <$> script
| i `elem` stats = Just (HasStatsInfo i)
| otherwise = Nothing

writeOutputTo :: Handle -> IO ()
writeOutputTo h = do
SavedOutput fullOutput _ _ <- outputReverse <$> readIORef savedOutput
forM_ fullOutput $ \(OutputLine lno ot t' msg) -> do
let tformat = "%a %d-%m-%Y %T"
tstr = formatTime defaultTimeLocale tformat t'
lineStr = if lno > 0
then printf " Line %s" (show lno)
else "" :: String
hPutStrLn h $ printf "[%s]%s (%s): %s" tstr lineStr (show ot) msg

writeOutputJS :: FilePath -> FilePath -> T.Text -> NGLessIO ()
writeOutputJS odir scriptName script = liftIO $ do
SavedOutput fullOutput fqStats mapStats <- outputReverse <$> readIORef savedOutput
Expand Down
5 changes: 3 additions & 2 deletions NGLess/StandardModules/Parallel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ executeLock1OrForAll funcname (NGOList entries) kwargs = do
release rk
registerFailHook $ do
let logfile = lockdir </> T.unpack e ++ ".failed"
withFile logfile WriteMode $ \h ->
hPutStrLn h "Execution failed" -- TODO output log here
withFile logfile WriteMode $ \h -> do
hPutStrLn h "Execution failed. Execution log:"
writeOutputTo h
case entries of
(NGOString _:_) -> return . NGOString $! fromMaybe e $ lookup e (zip saneentries entries')
_ -> case lookup e (zip saneentries entries) of
Expand Down
1 change: 1 addition & 0 deletions docs/sources/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ which will print ``my-sample``.
- Make ``print()`` accept ints and doubles as well as strings
- Added ``println`` function which works like ``print`` but prints a newline after the output.
- Added ``run_for_all`` function to ``parallel`` module, simplifying its `API <stdlib.html>`__.
- When using the ``parallel`` module and a job fails, writes the log to the corresponding ``.failed`` file

Version 1.4.2
-------------
Expand Down

0 comments on commit 0fa54db

Please sign in to comment.