@@ -196,6 +216,11 @@ getViewProgressWithWebSocketsR jobId = do
|]
+getViewProgressWithWebSocketsR :: Int -> Handler Html
+getViewProgressWithWebSocketsR jobId = do
+ webSockets $ consoleApp jobId
+ defaultLayout logWidget
+
runViewProgressAsynchronously :: (Channel -> Handler ()) -> Handler Value
runViewProgressAsynchronously action = runViewProgressGeneralized getJobIdAsJson action
-- where getJobIdAsJson jobId = return $ Number (scientific (toInteger jobId) 0)
@@ -208,9 +233,11 @@ runViewProgress' route action = runViewProgressGeneralized doRedirection action
runViewProgressGeneralized :: (Int -> Handler v) -> (Channel -> Handler ()) -> Handler v
runViewProgressGeneralized handler action = do
App {..} <- getYesod
- jobId <- randomInt
+ jobId' <- randomInt
+ -- we don't want negative numbers (so that nobody would be confused)
+ let jobId = abs jobId'
chan <- liftIO $ atom $ do
- chan <- newBroadcastTChan
+ chan <- newTChan
m <- readTVar jobs
writeTVar jobs $ IntMap.insert jobId chan m
return chan
@@ -221,10 +248,10 @@ runViewProgressGeneralized handler action = do
liftIO $ atom $ do
writeTChan chan $ Just "All done\n"
writeTChan chan Nothing
- m <- readTVar jobs
- writeTVar jobs $ IntMap.delete jobId m
+-- TODO we don't remove logs, they could clog up the memory
+-- m <- readTVar jobs
+-- writeTVar jobs $ IntMap.delete jobId m
handler jobId
-
data RepoCloningSpec = RepoCloningSpec {
cloningSpecRepo :: RepoSpec,
cloningSpecReferenceRepo :: RepoSpec
@@ -497,7 +524,7 @@ getViewProgressR jobId = do
m <- readTVar jobs
case IntMap.lookup jobId m of
Nothing -> return Nothing
- Just chan -> fmap Just $ dupTChan chan
+ Just chan -> fmap Just $ cloneTChan chan
case mchan of
Nothing -> notFound
Just chan -> respondSource typePlain $ do
diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs
index efd570f..938a9e6 100644
--- a/Handler/ShowChallenge.hs
+++ b/Handler/ShowChallenge.hs
@@ -1610,6 +1610,48 @@ challengeLayout withHeader challenge widget = do
getTestProgressR :: Int -> Int -> Handler TypedContent
getTestProgressR m d = runViewProgress $ doTestProgress m d
+getTestProgressJsonR :: Int -> Int -> Handler Value
+getTestProgressJsonR m d = do
+ _ <- requireAuthPossiblyByToken
+ runViewProgressAsynchronously $ doTestProgress m d
+
+declareTestProgressSwagger :: Declare (Definitions Schema) Swagger
+declareTestProgressSwagger = do
+ -- param schemas
+ let numberSchema = toParamSchema (Proxy :: Proxy Int)
+
+ numberResponse <- declareResponse (Proxy :: Proxy Int)
+
+ return $ mempty
+ & paths .~
+ fromList [ ("/api/test-progress/{num}/{delay}",
+ mempty & DS.get ?~ (mempty
+ & parameters .~ [ Inline $ mempty
+ & name .~ "num"
+ & description ?~ "The number up to which to count"
+ & required ?~ True
+ & schema .~ ParamOther (mempty
+ & in_ .~ ParamPath
+ & paramSchema .~ numberSchema),
+ Inline $ mempty
+ & name .~ "delay"
+ & description ?~ "Delay in seconds"
+ & required ?~ True
+ & schema .~ ParamOther (mempty
+ & in_ .~ ParamPath
+ & paramSchema .~ numberSchema)
+ ]
+ & produces ?~ MimeList ["application/json"]
+ & description ?~ "Counts up to a given number, returns an ID of an asynchronous job. This is just a sample end-point for testing logging of asynchronous jobs."
+ & at 200 ?~ Inline numberResponse))
+ ]
+
+testProgressApi :: Swagger
+testProgressApi = spec & definitions .~ defs
+ where
+ (defs, spec) = runDeclare declareTestProgressSwagger mempty
+
+
doTestProgress :: Int -> Int -> Channel -> Handler ()
doTestProgress m d chan = do
_ <- forM [1..m] $ (\i -> do
@@ -1617,3 +1659,32 @@ doTestProgress m d chan = do
liftIO $ threadDelay (d * 1000000)
return ())
return ()
+
+
+declareViewProgressWithWebSocketsSwagger :: Declare (Definitions Schema) Swagger
+declareViewProgressWithWebSocketsSwagger = do
+ -- param schemas
+ let numberSchema = toParamSchema (Proxy :: Proxy Int)
+
+ numberResponse <- declareResponse (Proxy :: Proxy Int)
+
+ return $ mempty
+ & paths .~
+ fromList [ ("/api/view-progress-with-web-sockets/{jobId}",
+ mempty & DS.get ?~ (mempty
+ & parameters .~ [ Inline $ mempty
+ & name .~ "jobId"
+ & description ?~ "The ID for the job to be shown"
+ & required ?~ True
+ & schema .~ ParamOther (mempty
+ & in_ .~ ParamPath
+ & paramSchema .~ numberSchema)]
+ & produces ?~ MimeList ["application/json"]
+ & description ?~ "Initiates a web socket communication with which progress logs can be read. Returns just the Job ID (the same number as the parameter)"
+ & at 200 ?~ Inline numberResponse))
+ ]
+
+viewProgressWithWebSockets :: Swagger
+viewProgressWithWebSockets = spec & definitions .~ defs
+ where
+ (defs, spec) = runDeclare declareViewProgressWithWebSocketsSwagger mempty
diff --git a/Handler/Swagger.hs b/Handler/Swagger.hs
index 7b0d06e..5858f80 100644
--- a/Handler/Swagger.hs
+++ b/Handler/Swagger.hs
@@ -31,6 +31,8 @@ apiDescription = generalApi
<> myTeamsApi
<> challengeImgApi
<> challengeRepoApi
+ <> testProgressApi
+ <> viewProgressWithWebSockets
generalApi :: Swagger
generalApi = (mempty :: Swagger)
diff --git a/README.md b/README.md
index 09902a6..0e68a7e 100644
--- a/README.md
+++ b/README.md
@@ -101,7 +101,9 @@ application, this feature is on the way).
5. Set _Web Origin_ for the `gonito` client in Keycloak (e.g. simply add `*` there).
-6. Set `JSON_WEB_KEY` variable to the content of the JWK key (or `GONITO_JSON_WEB_KEY` when using docker-compose)
+6. Add some test user, set up some first/last name for them.
+
+7. Set `JSON_WEB_KEY` variable to the content of the JWK key (or `GONITO_JSON_WEB_KEY` when using docker-compose)
and run Gonito.
If you create a new user, you need to run `/api/add-info` GET
diff --git a/config/routes b/config/routes
index 9aef83f..c865515 100644
--- a/config/routes
+++ b/config/routes
@@ -10,7 +10,10 @@
/view-progress/#Int ViewProgressR GET
/open-view-progress/#Int OpenViewProgressR GET
/view-progress-with-web-sockets/#Int ViewProgressWithWebSocketsR GET
+/api/view-progress-with-web-sockets/#Int ViewProgressWithWebSocketsJsonR GET
+/api/view-progress-log/#Int ViewProgressLogR GET
/test-progress/#Int/#Int TestProgressR GET
+/api/test-progress/#Int/#Int TestProgressJsonR GET
/list-challenges ListChallengesR GET
/api/list-challenges ListChallengesJsonR GET
diff --git a/static/test-gonito-as-backend.html b/static/test-gonito-as-backend.html
index ecd3d9a..1f69e59 100644
--- a/static/test-gonito-as-backend.html
+++ b/static/test-gonito-as-backend.html
@@ -1,6 +1,39 @@
+
+
+
@@ -101,5 +197,17 @@
+
+
+
+
+
+
+