chore(job): add sleep job for testing
also show running job workers
This commit is contained in:
parent
6b32cddeac
commit
ee5a79398f
@ -15,3 +15,5 @@ log-settings:
|
|||||||
|
|
||||||
auth-dummy-login: true
|
auth-dummy-login: true
|
||||||
server-session-acid-fallback: true
|
server-session-acid-fallback: true
|
||||||
|
|
||||||
|
job-workers: 20
|
||||||
@ -196,6 +196,7 @@ postAdminJobsR = do
|
|||||||
(First (Just act), jobMap) <- inp
|
(First (Just act), jobMap) <- inp
|
||||||
let jobSet = Map.keysSet . Map.filter id $ getDBFormResult (const False) jobMap
|
let jobSet = Map.keysSet . Map.filter id $ getDBFormResult (const False) jobMap
|
||||||
return (act, jobSet)
|
return (act, jobSet)
|
||||||
|
void . queueJob' $ JobSleep 42 -- debug add sleep job
|
||||||
(jobActRes, jobsTable) <- runDB (over _1 postprocess <$> dbTable jobsDBTableValidator jobsDBTable)
|
(jobActRes, jobsTable) <- runDB (over _1 postprocess <$> dbTable jobsDBTableValidator jobsDBTable)
|
||||||
|
|
||||||
formResult jobActRes $ \case
|
formResult jobActRes $ \case
|
||||||
@ -218,11 +219,20 @@ postAdminJobsR = do
|
|||||||
addMessageI (bool Success Warning $ rmvd < jobReq) (MsgTableJobActDeleteFeedback rmvd jobReq)
|
addMessageI (bool Success Warning $ rmvd < jobReq) (MsgTableJobActDeleteFeedback rmvd jobReq)
|
||||||
reloadKeepGetParams AdminJobsR
|
reloadKeepGetParams AdminJobsR
|
||||||
|
|
||||||
|
-- gather some data on job worles
|
||||||
|
(nrWorkers, jobStateVar) <- getsYesod (view _appJobWorkers &&& appJobState)
|
||||||
|
jState <- atomically $ tryReadTMVar jobStateVar
|
||||||
|
let running = Map.size . jobWorkers <$> jState
|
||||||
|
|
||||||
siteLayoutMsg MsgMenuAdminJobs $ do
|
siteLayoutMsg MsgMenuAdminJobs $ do
|
||||||
setTitleI MsgMenuAdminJobs
|
setTitleI MsgMenuAdminJobs
|
||||||
[whamlet|
|
[whamlet|
|
||||||
^{jobsTable}
|
<section>
|
||||||
|
^{jobsTable}
|
||||||
|
<section>
|
||||||
|
<ul>
|
||||||
|
<li> #{running} job workers currently running
|
||||||
|
<li> #{nrWorkers} job workers configured to run
|
||||||
|]
|
|]
|
||||||
where
|
where
|
||||||
doEnc :: ToJSON a => a -> _
|
doEnc :: ToJSON a => a -> _
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
module Jobs.Handler.SendTestEmail
|
module Jobs.Handler.SendTestEmail
|
||||||
( dispatchJobSendTestEmail
|
( dispatchJobSendTestEmail
|
||||||
|
, dispatchJobSleep
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
@ -14,6 +15,8 @@ import Text.Hamlet
|
|||||||
-- import Handler.Utils.I18n
|
-- import Handler.Utils.I18n
|
||||||
-- import Text.Blaze.Internal
|
-- import Text.Blaze.Internal
|
||||||
|
|
||||||
|
import UnliftIO.Concurrent (threadDelay)
|
||||||
|
|
||||||
dispatchJobSendTestEmail :: Email -> MailContext -> JobHandler UniWorX
|
dispatchJobSendTestEmail :: Email -> MailContext -> JobHandler UniWorX
|
||||||
dispatchJobSendTestEmail jEmail jMailContext = JobHandlerException . mailT jMailContext $ do
|
dispatchJobSendTestEmail jEmail jMailContext = JobHandlerException . mailT jMailContext $ do
|
||||||
_mailTo .= [Address Nothing jEmail]
|
_mailTo .= [Address Nothing jEmail]
|
||||||
@ -61,3 +64,12 @@ dispatchJobSendTestEmail jEmail jMailContext = JobHandlerException . mailT jMail
|
|||||||
--
|
--
|
||||||
--test2 <- liftHandler $(i18nHamletFile "test")
|
--test2 <- liftHandler $(i18nHamletFile "test")
|
||||||
--addHtmlMarkdownAlternatives test2
|
--addHtmlMarkdownAlternatives test2
|
||||||
|
|
||||||
|
|
||||||
|
dispatchJobSleep :: Int -> JobHandler UniWorX
|
||||||
|
dispatchJobSleep sleepTime = JobHandlerAtomic act
|
||||||
|
where
|
||||||
|
act = do
|
||||||
|
$logInfoS "JOBS" [st|Sleep job #{sleepTime}s started.|]
|
||||||
|
threadDelay (sleepTime * 1000000)
|
||||||
|
$logInfoS "JOBS" [st|Sleep job #{sleepTime}s ended.|]
|
||||||
@ -141,8 +141,9 @@ data Job
|
|||||||
| JobLmsReports { jQualification :: QualificationId }
|
| JobLmsReports { jQualification :: QualificationId }
|
||||||
| JobPrintAck
|
| JobPrintAck
|
||||||
| JobPrintAckAgain
|
| JobPrintAckAgain
|
||||||
|
| JobSleep { jSleep :: Int } -- dummy job that just sleeps to test job system
|
||||||
deriving (Eq, Ord, Show, Read, Generic)
|
deriving (Eq, Ord, Show, Read, Generic)
|
||||||
|
|
||||||
data Notification
|
data Notification
|
||||||
= NotificationSubmissionRated { nSubmission :: SubmissionId }
|
= NotificationSubmissionRated { nSubmission :: SubmissionId }
|
||||||
| NotificationSheetActive { nSheet :: SheetId }
|
| NotificationSheetActive { nSheet :: SheetId }
|
||||||
|
|||||||
Reference in New Issue
Block a user