forked from filipg/gonito
Whether using web socket for showing progress is configurable
This commit is contained in:
parent
0bc680c7ae
commit
d02d3a824a
@ -96,7 +96,13 @@ browsableGitRepo bareRepoName
|
|||||||
|
|
||||||
|
|
||||||
runViewProgress :: (Channel -> Handler ()) -> Handler TypedContent
|
runViewProgress :: (Channel -> Handler ()) -> Handler TypedContent
|
||||||
runViewProgress = runViewProgress' ViewProgressR
|
runViewProgress action = do
|
||||||
|
app <- getYesod
|
||||||
|
let viewingProgressStyle = appViewingProgressStyle $ appSettings app
|
||||||
|
runViewProgress' (case viewingProgressStyle of
|
||||||
|
WithWebSockets -> ViewProgressWithWebSocketsR
|
||||||
|
WithPlainText -> ViewProgressR)
|
||||||
|
action
|
||||||
|
|
||||||
runOpenViewProgress :: (Channel -> Handler ()) -> Handler TypedContent
|
runOpenViewProgress :: (Channel -> Handler ()) -> Handler TypedContent
|
||||||
runOpenViewProgress = runViewProgress' OpenViewProgressR
|
runOpenViewProgress = runViewProgress' OpenViewProgressR
|
||||||
@ -147,6 +153,10 @@ getViewProgressWithWebSocketsR jobId = do
|
|||||||
background-color: black;
|
background-color: black;
|
||||||
padding: 10pt;
|
padding: 10pt;
|
||||||
}
|
}
|
||||||
|
#outwindow pre {
|
||||||
|
color: white;
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
#wait {
|
#wait {
|
||||||
animation: blink 1s linear infinite;
|
animation: blink 1s linear infinite;
|
||||||
}
|
}
|
||||||
@ -172,7 +182,7 @@ getViewProgressWithWebSocketsR jobId = do
|
|||||||
conn = new WebSocket(url);
|
conn = new WebSocket(url);
|
||||||
|
|
||||||
conn.onmessage = function(e) {
|
conn.onmessage = function(e) {
|
||||||
var p = document.createElement("p");
|
var p = document.createElement("pre");
|
||||||
p.appendChild(document.createTextNode(e.data));
|
p.appendChild(document.createTextNode(e.data));
|
||||||
output.appendChild(p);
|
output.appendChild(p);
|
||||||
};
|
};
|
||||||
|
@ -1334,12 +1334,12 @@ challengeLayout withHeader challenge widget = do
|
|||||||
$(widgetFile "challenge")
|
$(widgetFile "challenge")
|
||||||
|
|
||||||
getTestProgressR :: Int -> Handler TypedContent
|
getTestProgressR :: Int -> Handler TypedContent
|
||||||
getTestProgressR m = runViewProgressWithWebSockets $ doTestProgress m
|
getTestProgressR m = runViewProgress $ doTestProgress m
|
||||||
|
|
||||||
doTestProgress :: Int -> Channel -> Handler ()
|
doTestProgress :: Int -> Channel -> Handler ()
|
||||||
doTestProgress m chan = do
|
doTestProgress m chan = do
|
||||||
forM [1..m] $ (\i -> do
|
forM [1..m] $ (\i -> do
|
||||||
msg chan $ (Data.Text.pack $ show i)
|
msg chan $ (Data.Text.pack $ ("GO\n" ++ show i))
|
||||||
liftIO $ threadDelay 1000000
|
liftIO $ threadDelay 1000000
|
||||||
return ())
|
return ())
|
||||||
return ()
|
return ()
|
||||||
|
14
Settings.hs
14
Settings.hs
@ -42,6 +42,17 @@ toLeaderboardStyle :: Text -> LeaderboardStyle
|
|||||||
toLeaderboardStyle "by-tag" = ByTag
|
toLeaderboardStyle "by-tag" = ByTag
|
||||||
toLeaderboardStyle _ = BySubmitter
|
toLeaderboardStyle _ = BySubmitter
|
||||||
|
|
||||||
|
-- How showing progress for asynchronous operations
|
||||||
|
-- such as creating a challenge, submitting a submission, etc.
|
||||||
|
-- is realized technically.
|
||||||
|
data ViewingProgressStyle = WithWebSockets | WithPlainText
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
toViewingProgressStyle :: Text -> ViewingProgressStyle
|
||||||
|
toViewingProgressStyle "with-web-sockets" = WithWebSockets
|
||||||
|
toViewingProgressStyle _ = WithPlainText
|
||||||
|
|
||||||
|
|
||||||
-- | Runtime settings to configure this application. These settings can be
|
-- | Runtime settings to configure this application. These settings can be
|
||||||
-- loaded from various sources: defaults, environment variables, config files,
|
-- loaded from various sources: defaults, environment variables, config files,
|
||||||
-- theoretically even a database.
|
-- theoretically even a database.
|
||||||
@ -96,6 +107,7 @@ data AppSettings = AppSettings
|
|||||||
-- ^ Are challenges, submission, etc. visible without logging in
|
-- ^ Are challenges, submission, etc. visible without logging in
|
||||||
, appIsPublic :: Bool
|
, appIsPublic :: Bool
|
||||||
, appJSONWebKey :: Maybe JWK.Jwk
|
, appJSONWebKey :: Maybe JWK.Jwk
|
||||||
|
, appViewingProgressStyle :: ViewingProgressStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
instance FromJSON AppSettings where
|
instance FromJSON AppSettings where
|
||||||
@ -143,6 +155,8 @@ instance FromJSON AppSettings where
|
|||||||
|
|
||||||
appJSONWebKey <- o .:? "json-web-key"
|
appJSONWebKey <- o .:? "json-web-key"
|
||||||
|
|
||||||
|
appViewingProgressStyle <- toViewingProgressStyle <$> o .: "viewing-progress-style"
|
||||||
|
|
||||||
return AppSettings {..}
|
return AppSettings {..}
|
||||||
|
|
||||||
-- | Settings for 'widgetFile', such as which template languages to support and
|
-- | Settings for 'widgetFile', such as which template languages to support and
|
||||||
|
@ -17,6 +17,15 @@ new-best-result-slack-hook: "_env:NEW_BEST_RESULT_SLACK_HOOK:"
|
|||||||
server-ssh-public-key: "_env:SERVER_SSH_PUBLIC_KEY:"
|
server-ssh-public-key: "_env:SERVER_SSH_PUBLIC_KEY:"
|
||||||
is-public: "_env:IS_PUBLIC:true"
|
is-public: "_env:IS_PUBLIC:true"
|
||||||
|
|
||||||
|
# How the output of asynchronous operations is presented
|
||||||
|
# - with-plain-text - just plain text shown by the browser;
|
||||||
|
# pros: it works with anything, cons: with NGINX the output
|
||||||
|
# is not shown progressively, only when it is finished
|
||||||
|
# - with-web-sockets - using web sockets and JavaScripts, pros:
|
||||||
|
# nicer visually, fully works with NGINX, cons: does not work
|
||||||
|
# with lighttpd
|
||||||
|
viewing-progress-style: "_env:VIEWING_PROGRESS_STYLE:with-plain-text"
|
||||||
|
|
||||||
# Optional values with the following production defaults.
|
# Optional values with the following production defaults.
|
||||||
# In development, they default to the inverse.
|
# In development, they default to the inverse.
|
||||||
#
|
#
|
||||||
|
@ -26,6 +26,7 @@ services:
|
|||||||
- AUTO_OPENING=${GONITO_AUTO_OPENING:-false}
|
- AUTO_OPENING=${GONITO_AUTO_OPENING:-false}
|
||||||
- IS_PUBLIC=${GONITO_IS_PUBLIC:-true}
|
- IS_PUBLIC=${GONITO_IS_PUBLIC:-true}
|
||||||
- JSON_WEB_KEY=${JSON_WEB_KEY}
|
- JSON_WEB_KEY=${JSON_WEB_KEY}
|
||||||
|
- VIEWING_PROGRESS_STYLE=${GONITO_VIEWING_PROGRESS_STYLE:-with-web-sockets}
|
||||||
expose:
|
expose:
|
||||||
- "3000"
|
- "3000"
|
||||||
volumes:
|
volumes:
|
||||||
|
@ -22,10 +22,11 @@ http {
|
|||||||
proxy_pass http://gonito;
|
proxy_pass http://gonito;
|
||||||
proxy_redirect off;
|
proxy_redirect off;
|
||||||
|
|
||||||
proxy_read_timeout 600;
|
proxy_read_timeout 6000;
|
||||||
proxy_connect_timeout 600;
|
proxy_connect_timeout 6000;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Connection "";
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "Upgrade";
|
||||||
}
|
}
|
||||||
|
|
||||||
listen 443 ssl;
|
listen 443 ssl;
|
||||||
|
@ -10,4 +10,5 @@ GONITO_AUTO_OPENING=false
|
|||||||
NGINX_CERTIFICATE_DIR=/home/user/certs
|
NGINX_CERTIFICATE_DIR=/home/user/certs
|
||||||
GONITO_IS_PUBLIC=true
|
GONITO_IS_PUBLIC=true
|
||||||
GONITO_SSH_DIRECTORY=/home/user/.ssh
|
GONITO_SSH_DIRECTORY=/home/user/.ssh
|
||||||
|
GONITO_VIEWING_PROGRESS_STYLE=with-web-sockets
|
||||||
JSON_WEB_KEY="{\"kty\":\"RSA\", \"alg\":\"RS256\", \"use\":\"sig\", \"kid\":\"h01jmt_bD-1Di8i_GYbEV2a4NxhptzySHO-R8VuNHVA\", \"e\":\"AQAB\", \"n\": \"qG1elE6KPW3BYMxNpgK73MoksvbrUSfpRY4z9hU5iMsJREyD5Ar6XpjM1xAr6G7xglnOoumPC9o6FqhDHihm6QdJ5s5MA9ZyGkbi--kvy9Qc2d_VIGU-UR4vwyk3hAwXOFLhoknpQrJBJmMQvGFdas1Yr-m9EIWwT1zN7neHZkRUYZSVyQw_XghtMIWAUsLnhr6mM7nstHLafgxe5Qamzuc4K5EC_qipFXu4ugYkMDnaknlhkT43m7tcduVDnv5GV_4dBesF7FRII8tgUQWyw3Ty_FIoq43SInUPU_9cxA-qPGQz5C50th2aJl1z1snpLWS_1Zfsa8lnFsMj8_oh6w\"}"
|
JSON_WEB_KEY="{\"kty\":\"RSA\", \"alg\":\"RS256\", \"use\":\"sig\", \"kid\":\"h01jmt_bD-1Di8i_GYbEV2a4NxhptzySHO-R8VuNHVA\", \"e\":\"AQAB\", \"n\": \"qG1elE6KPW3BYMxNpgK73MoksvbrUSfpRY4z9hU5iMsJREyD5Ar6XpjM1xAr6G7xglnOoumPC9o6FqhDHihm6QdJ5s5MA9ZyGkbi--kvy9Qc2d_VIGU-UR4vwyk3hAwXOFLhoknpQrJBJmMQvGFdas1Yr-m9EIWwT1zN7neHZkRUYZSVyQw_XghtMIWAUsLnhr6mM7nstHLafgxe5Qamzuc4K5EC_qipFXu4ugYkMDnaknlhkT43m7tcduVDnv5GV_4dBesF7FRII8tgUQWyw3Ty_FIoq43SInUPU_9cxA-qPGQz5C50th2aJl1z1snpLWS_1Zfsa8lnFsMj8_oh6w\"}"
|
||||||
|
Loading…
Reference in New Issue
Block a user