1{-# LANGUAGE TypeApplications #-}
3module Control.Task.Scheduler.Query
15import Control.Monad.IO.Unlift
18import Data.Aeson hiding (Result (..))
20import qualified Data.Text as T
23import GHC.Generics (Generic)
25import qualified Generics.SOP as SOP
27import Squeal.PostgreSQL
31 (StaticPQ m, Task t s, WithLog env Message m, MonadUnliftIO m) =>
34scheduleTaskQuery task = do
35 logInfo . T.pack $ "schdeuling task: " <> show task
40 Set (param @1) `as` #task
41 :* Set (param @2) `as` #payload
42 :* Default `as` #creation_time
43 :* Default `as` #started
44 :* Default `as` #failures
47 (OnConstraint #pk_task_payload)
48 (DoUpdate (Default `as` #creation_time) [])
51 dbWrite (const $ return ()) $
54 (symbolVal @s Proxy, Jsonb $ toJSON task)
58 (StaticPQ m, Task t s, WithLog env Message m, MonadUnliftIO m) =>
61completeTaskQuery payload = do
62 let task = symbolVal @s Proxy
63 logInfo . T.pack $ "Completing task: " <> task <> " with payload " <> show payload
64 let query :: Manipulation_ Schema (String, Jsonb Value) ()
68 (param @1 .== #task .&& param @2 .== #payload)
69 dbWrite (const $ return ()) $
72 (symbolVal @s Proxy, Jsonb $ toJSON payload)
76 (StaticPQ m, Task t s, WithLog env Message m, MonadUnliftIO m) =>
79rescheduleTaskQuery payload = do
80 let task = symbolVal @s Proxy
82 "reschdeuling task: " <> task
85 let query :: Manipulation_ Schema (String, Jsonb Value) ()
89 ( Default `as` #creation_time
90 :* Default `as` #started
91 :* Set (#failures + 1) `as` #failures
93 (param @1 .== #task .&& param @2 .== #payload)
94 dbWrite (const $ return ()) $
97 (symbolVal @s Proxy, Jsonb $ toJSON payload)
101 (StaticPQ m, WithLog env Message m, MonadUnliftIO m) =>
105pickTasksQuery tasks limitCount = do
106 logDebug $ "reading tasks " <> T.unwords (T.pack <$> tasks)
107 let query :: Query_ Schema () PickedTask
111 :* #payload `as` #payload
112 :* #creation_time `as` #creationTime
114 ( from (table #tasks)
115 & where_ (#task `in_` (literal <$> tasks))
116 & where_ (not_ . notNull $ #started)
117 & where_ (#failures .< 20)
118 & orderBy [#creation_time & Asc]
120 & orderBy [#creation_time & Desc]
122 startedMan :: Manipulation_ Schema (String, Jsonb Value) ()
126 ( Set true `as` #started
128 (param @1 .== #task .&& param @2 .== #payload)
129 dbWrite (const $ return []) $ do
130 pickedTasks <- runQuery query >>= getRows
131 traversePrepared_ startedMan $ (task &&& payload) <$> pickedTasks
137 payload :: Jsonb Value,
138 creationTime :: UTCTime
140 deriving (Eq, Show, Generic, SOP.Generic, SOP.HasDatatypeInfo)
143 (StaticPQ m, WithLog env Message m, MonadUnliftIO m) =>
146 let startAll :: Manipulation_ Schema () ()
150 ( Set false `as` #started
153 dbWrite (const $ return ()) $
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list