1{-# LANGUAGE TypeApplications #-}
3module Control.Task.Scheduler.Query
13import Control.Monad.IO.Unlift
16import Data.Aeson hiding (Result (..))
18import qualified Data.Text as T
21import GHC.Generics (Generic)
23import qualified Generics.SOP as SOP
25import Squeal.PostgreSQL
29 (StaticPQ m, Task t s, WithLog env Message m, MonadUnliftIO m) =>
32scheduleTaskQuery task = do
33 logInfo . T.pack $ "schdeuling task: " <> show task
38 Set (param @1) `as` #task
39 :* Set (param @2) `as` #payload
40 :* Default `as` #creation_time
43 (OnConstraint #pk_task_payload)
44 (DoUpdate (Default `as` #creation_time) [])
47 dbWrite (const $ return ()) $
50 (symbolVal @s Proxy, Jsonb $ toJSON task)
54 (StaticPQ m, Task t s, WithLog env Message m, MonadUnliftIO m) =>
57completeTaskQuery payload = do
58 let task = symbolVal @s Proxy
59 logInfo . T.pack $ "Completing task: " <> task <> " with payload " <> show payload
60 let query :: Manipulation_ Schema (String, Jsonb Value) ()
64 (param @1 .== #task .&& param @2 .== #payload)
65 dbWrite (const $ return ()) $
68 (symbolVal @s Proxy, Jsonb $ toJSON payload)
72 (StaticPQ m, Task t s, WithLog env Message m, MonadUnliftIO m) =>
75rescheduleTaskQuery payload = do
76 let task = symbolVal @s Proxy
78 "reschdeuling task: " <> task
81 let query :: Manipulation_ Schema (String, Jsonb Value) ()
85 (Default `as` #creation_time)
86 (param @1 .== #task .&& param @2 .== #payload)
87 dbWrite (const $ return ()) $
90 (symbolVal @s Proxy, Jsonb $ toJSON payload)
94 (StaticPQ m, WithLog env Message m, MonadUnliftIO m) =>
98pickTasksQuery tasks limitCount = do
99 logDebug "reading tasks"
100 let query :: Query_ Schema () PickedTask
104 :* #payload `as` #payload
105 :* #creation_time `as` #creationTime
107 ( from (table #tasks)
108 & where_ (#task `in_` (literal <$> tasks))
109 & orderBy [#creation_time & Asc]
112 dbRead (const $ return []) $
113 runQuery query >>= getRows
118 payload :: Jsonb Value,
119 creationTime :: UTCTime
121 deriving (Eq, Show, Generic, SOP.Generic, SOP.HasDatatypeInfo)
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