From 9f75243ada97ad055dc0b02991695821eda91990 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 17 Jul 2023 00:53:02 +0200 Subject: [haskell] Trigger a program restart when the api client encounters a server reset --- haskell/package.yaml | 1 + haskell/src/SpaceTraders/APIClient/Client.hs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/haskell/package.yaml b/haskell/package.yaml index 567b06c..8ecfa55 100644 --- a/haskell/package.yaml +++ b/haskell/package.yaml @@ -27,6 +27,7 @@ dependencies: - text - time - transformers +- unix ghc-options: - -Wall diff --git a/haskell/src/SpaceTraders/APIClient/Client.hs b/haskell/src/SpaceTraders/APIClient/Client.hs index 87147b6..0f0cf27 100644 --- a/haskell/src/SpaceTraders/APIClient/Client.hs +++ b/haskell/src/SpaceTraders/APIClient/Client.hs @@ -23,6 +23,8 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as T import Network.HTTP.Simple import Network.HTTP.Types.Status +import System.Environment +import System.Posix.Process import SpaceTraders.APIClient.Errors import SpaceTraders.APIClient.Pagination @@ -81,4 +83,9 @@ sendPaginated request = do Right (APIRateLimit r) -> do threadDelay (1_000_000 * (round $ retryAfter r)) sendPaginated request + Right (APIResetHappened _) -> do + p <- getExecutablePath + a <- getArgs + e <- getEnvironment + executeFile p False a (Just e) Right e -> return $ Left e -- cgit v1.2.3