summaryrefslogtreecommitdiff
path: root/haskell
diff options
context:
space:
mode:
authorJulien Dessaux2023-07-17 00:53:02 +0200
committerJulien Dessaux2023-07-17 00:53:02 +0200
commit9f75243ada97ad055dc0b02991695821eda91990 (patch)
treecfe5d6b5790307d7b714e64ff1a7896d4d0be0a8 /haskell
parent[haskell] Add a SpaceTradersT and handle server reset api message (diff)
downloadspacetraders-9f75243ada97ad055dc0b02991695821eda91990.tar.gz
spacetraders-9f75243ada97ad055dc0b02991695821eda91990.tar.bz2
spacetraders-9f75243ada97ad055dc0b02991695821eda91990.zip
[haskell] Trigger a program restart when the api client encounters a server reset
Diffstat (limited to 'haskell')
-rw-r--r--haskell/package.yaml1
-rw-r--r--haskell/src/SpaceTraders/APIClient/Client.hs7
2 files changed, 8 insertions, 0 deletions
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