@@ -30,7 +30,6 @@ import Data.Submission.Query
3030import Data.Tasks.Build
3131import Data.Tasks.StatusUpdate
3232import qualified Data.Text as T
33−import Data.Time.Clock
3433import Data.Yaml
3534import GHC.Generics
3635import GitHub hiding (Accept)
@@ -50,6 +49,7 @@ import Server.Config
5049import Server.Html
5150import Server.Schema
5251import Squeal.PostgreSQL
52+import System.IO
5353import Text.Blaze.Html
5454import UnliftIO.Exception (catch, displayException, handleAny, throwIO, try)
5555
@@ -75,18 +75,14 @@ type API =
7575 :> Post '[HTML] Markup
7676 :<|> "results" :> Capture "task name" String :> Get '[CSV, HTML] [Score]
7777
78−webhookInstallation :: WithLog env Message m => RepoWebhookEvent -> ((), InstallationEvent) -> m ()
78+webhookInstallation :: MonadIO m => RepoWebhookEvent -> ((), InstallationEvent) -> m ()
7979webhookInstallation _ ((), ev) =
80− logInfo . T.pack . show $ ev
80+ liftIO $ do
81+ print ev
82+ hFlush stdout
8183
8284webhookPushEvent ::
83− ( StaticPQ m,
84− MonadReader (ServerData m) m,
85− MonadUnliftIO m,
86− HasTasks m,
87− MonadError ServerError m,
88− WithLog env Message m
89− ) =>
85+ (StaticPQ m, MonadReader (ServerData m) m, MonadUnliftIO m, HasTasks m, MonadError ServerError m) =>
9086 RepoWebhookEvent ->
9187 ((), PushEvent) ->
9288 m ()
@@ -104,28 +100,18 @@ webhookPushEvent _ ((), ev) = do
104100 M.takeWhileAntitone (repoName >) tasks
105101 case task of
106102 Just (name, TaskConfig {..}) | T.take (T.length name) repoName == name -> do
107− nowTime <- liftIO getCurrentTime
108− if nowTime > deadline
109− then do
110− deadlineHasPassedStatus (N owner) (N repoName) (N sha)
111− createSubmission $
112− Submission
113− user
114− (T.unpack fullRepoName)
115− (T.unpack name)
116− (T.unpack sha)
117− (Jsonb PastDeadline)
118− else do
119− schedulePendingStatus (N owner) (N repoName) (N sha)
120− createSubmission $
121− Submission
122− user
123− (T.unpack fullRepoName)
124− (T.unpack name)
125− (T.unpack sha)
126− (Jsonb BuildScheduled)
127− scheduleTask $ Build prebuild dockerfile (N owner) (N repoName) (N sha) timeoutMinutes
128− logInfo . T.pack . show $ ev
103+ schedulePendingStatus (N owner) (N repoName) (N sha)
104+ createSubmission $
105+ Submission
106+ user
107+ (T.unpack fullRepoName)
108+ (T.unpack name)
109+ (T.unpack sha)
110+ (Jsonb BuildScheduled)
111+ scheduleTask $ Build prebuild dockerfile (N owner) (N repoName) (N sha) timeoutMinutes
112+ liftIO $ do
113+ print ev
114+ hFlush stdout
129115 _ -> return ()
130116
131117retestSubmission ::
@@ -175,9 +161,9 @@ instance MonadError ServerError (ServerM schema) where
175161server :: ServerT API (ServerM Schema)
176162server = (webhookInstallation :<|> webhookPushEvent) :<|> getSubmissionR :<|> retestSubmission :<|> getResults
177163
178−runServer :: FilePath -> IO ()
179−runServer config = do
180− c@Config {..} <- getConfig config
164+runServer :: IO ()
165+runServer = do
166+ c@Config {..} <- getConfig
181167 print c
182168 pem <- BS.readFile appPkPemPath
183169 appPkPem <- case readRsaPem pem of
@@ -329,21 +315,6 @@ instance (MonadReader (ServerData m) m, StaticPQ m, MonadUnliftIO m) => HasGithu
329315 newStatusContext = Just c
330316 }
331317 scheduleTask status
332− deadlineHasPassedStatus nOwner@(N owner) nRepo@(N repo) nCommit@(N sha) = do
333− h <- asks baseUrl
334− c <- asks context
335− let status =
336− StatusUpdate
337− nOwner
338− nRepo
339− nCommit
340− NewStatus
341− { newStatusState = StatusError,
342− newStatusTargetUrl = Just . URL $ h <> "/submission/" <> owner <> "/" <> repo <> "/" <> sha,
343− newStatusDescription = Just "The deadline has passed ⏰",
344− newStatusContext = Just c
345− }
346− scheduleTask status
347318
348319instance (MonadReader (ServerData n) m) => HasDockerInfo m where
349320 getDockerUrl = asks dockerUrl
@@ -354,8 +325,7 @@ data TaskConfig
354325 = TaskConfig
355326 { prebuild :: String,
356327 dockerfile :: String,
357− timeoutMinutes :: Int,
358− deadline :: UTCTime
328+ timeoutMinutes :: Int
359329 }
360330 deriving stock (Show, Eq, Generic)
361331 deriving anyclass (FromJSON, ToJSON)