on master help sign in
renaming to odd-jobs
commitabf3cc6f88fee7bf703c0eaf6f23d8f30e5bfaf3 authorSaurabh Nanda <saurabh@vacationlabs.com> dateSat 17 Aug 2019, 12:05 (7 years ago) parent06631ce
12 files changed+131−31
dev/DevelMain.hs+1−1 package.yaml+17−9 src/PGQueue/Endpoints.hs → src/OddJobs/Endpoints.hs+5−5 src/PGQueue/Job.hs → src/OddJobs/Job.hs+2−2 src/PGQueue/Links.hs → src/OddJobs/Links.hs+2−2 src/PGQueue/Migrations.hs → src/OddJobs/Migrations.hs+4−4 src/PGQueue/Types.hs → src/OddJobs/Types.hs+1−1 src/PGQueue/Web.hs → src/OddJobs/Web.hs+3−3 src/UI.hs+2 test/Test.hs+4−4 test/Try.hs+28 test/Try2.hs+62
dev/DevelMain.hs+1−1
@@ -30,7 +30,7 @@ import GHC.Word (Word32)
3030import Network.Wai.Handler.Warp (defaultSettings, runSettings,
3131 setPort)
3232
33−import PGQueue.Endpoints (startApp, stopApp)
33+import OddJobs.Endpoints (startApp, stopApp)
3434-- import qualified ElmCodeGen
3535
3636-- | Start or restart the server.
package.yaml+17−9
@@ -1,7 +1,9 @@
1−name: haskell-pg-queue
1+name: odd-jobs
22version: 0.1.0.0
3−#synopsis:
4−#description:
3+synopsis: A full-featured PostgreSQL-backed job queue (with an admin UI)
4+description: |
5+ Something long comes here
6+ Something very long
57homepage: https://github.com/githubuser/haskell-pg-queue#readme
68license: BSD3
79author: Saurabh Nanda
@@ -11,8 +13,12 @@ category: Web
1113extra-source-files:
1214- README.md
1315
14−ghc-options: -Wall -fno-warn-orphans -fno-warn-unused-imports -fno-warn-dodgy-exports -O0 -threaded
15−
16+ghc-options:
17+ - -Wall
18+ - -fno-warn-orphans
19+ - -fno-warn-unused-imports
20+ - -fno-warn-dodgy-exports
21+ - -O0
1622
1723default-extensions:
1824 - NamedFieldPuns
@@ -66,10 +72,10 @@ library:
6672 - src
6773 - dev
6874 exposed-modules:
69− - PGQueue.Job
70− - PGQueue.Migrations
71− - PGQueue.Web
72− - PGQueue.Endpoints
75+ - OddJobs.Job
76+ - OddJobs.Migrations
77+ - OddJobs.Web
78+ - OddJobs.Endpoints
7379 - DevelMain
7480
7581# executables:
@@ -82,6 +88,8 @@ library:
8288
8389tests:
8490 jobrunner:
91+ ghc-options:
92+ - -threaded
8593 main: Test
8694 source-dirs: test
8795 dependencies:
src/PGQueue/Endpoints.hs → src/OddJobs/Endpoints.hsrenamed+5−5
@@ -1,10 +1,10 @@
11{-# LANGUAGE TypeOperators, DeriveGeneric, NamedFieldPuns, DataKinds, StandaloneDeriving, FlexibleContexts #-}
22
3−module PGQueue.Endpoints where
3+module OddJobs.Endpoints where
44
5−import PGQueue.Web as Web
6−import PGQueue.Job as Job
7−import PGQueue.Types
5+import OddJobs.Web as Web
6+import OddJobs.Job as Job
7+import OddJobs.Types
88import GHC.Generics
99
1010import Servant
@@ -33,7 +33,7 @@ import Data.Maybe (fromMaybe)
3333import Data.Text.Conversions (fromText, toText)
3434import Control.Applicative ((<|>))
3535import Data.Time.Convenience as Time
36−import qualified PGQueue.Links as Links
36+import qualified OddJobs.Links as Links
3737import Data.List ((\\))
3838
3939startApp :: IO ()
src/PGQueue/Job.hs → src/OddJobs/Job.hsrenamed+2−2
@@ -1,5 +1,5 @@
11{-# LANGUAGE RankNTypes, FlexibleInstances, FlexibleContexts, PartialTypeSignatures, TupleSections, DeriveGeneric, UndecidableInstances #-}
2−module PGQueue.Job
2+module OddJobs.Job
33 ( jobMonitor
44 , jobEventListener
55 , jobPoller
@@ -23,7 +23,7 @@ module PGQueue.Job
2323 )
2424where
2525
26−import PGQueue.Types
26+import OddJobs.Types
2727import Data.Pool
2828import Data.Text as T
2929import Database.PostgreSQL.Simple as PGS
src/PGQueue/Links.hs → src/OddJobs/Links.hsrenamed+2−2
@@ -1,10 +1,10 @@
11{-# LANGUAGE RecordWildCards, OverloadedStrings #-}
22
3−module PGQueue.Links where
3+module OddJobs.Links where
44
55import Servant
66import Servant.API.Generic
7−import PGQueue.Web (Routes(..))
7+import OddJobs.Web (Routes(..))
88import Data.String.Conv
99import Data.Text
1010
src/PGQueue/Migrations.hs → src/OddJobs/Migrations.hsrenamed+4−4
@@ -1,12 +1,12 @@
1−module PGQueue.Migrations
2− ( module PGQueue.Migrations
3− , module PGQueue.Types
1+module OddJobs.Migrations
2+ ( module OddJobs.Migrations
3+ , module OddJobs.Types
44 )
55where
66
77import Database.PostgreSQL.Simple as PGS
88import Data.Functor (void)
9−import PGQueue.Types
9+import OddJobs.Types
1010
1111createJobTableQuery :: TableName -> Query
1212createJobTableQuery tname = "CREATE TABLE " <> tname <>
src/PGQueue/Types.hs → src/OddJobs/Types.hsrenamed+1−1
@@ -1,4 +1,4 @@
1−module PGQueue.Types where
1+module OddJobs.Types where
22
33import Database.PostgreSQL.Simple as PGS
44
src/PGQueue/Web.hs → src/OddJobs/Web.hsrenamed+3−3
@@ -1,8 +1,8 @@
11{-# LANGUAGE DeriveGeneric, NamedFieldPuns, TypeOperators, DataKinds #-}
2−module PGQueue.Web where
2+module OddJobs.Web where
33
4−import PGQueue.Types
5−import PGQueue.Job as Job
4+import OddJobs.Types
5+import OddJobs.Job as Job
66import Data.Time
77import Data.Aeson as Aeson
88import Data.Text as T
src/UI.hsnew file+2
@@ -0,0 +1,2 @@
1+module UI where
2+
test/Test.hs+4−4
@@ -2,8 +2,8 @@
22module Test where
33
44import Test.Tasty as Tasty
5−import qualified PGQueue.Migrations as Migrations
6−import qualified PGQueue.Job as Job
5+import qualified OddJobs.Migrations as Migrations
6+import qualified OddJobs.Job as Job
77import Database.PostgreSQL.Simple as PGS
88import Data.Functor (void)
99import Data.Pool as Pool
@@ -15,7 +15,7 @@ import Control.Monad.Reader
1515import Data.Aeson as Aeson
1616import Control.Concurrent.Lifted
1717import Control.Concurrent.Async.Lifted
18−import PGQueue.Job (Job(..), JobId)
18+import OddJobs.Job (Job(..), JobId)
1919import System.Log.FastLogger (fromLogStr, withFastLogger, LogType(..), defaultBufSize, FastLogger, FileLogSpec(..))
2020import Data.String.Conv (toS)
2121import Data.Time
@@ -30,7 +30,7 @@ import qualified Data.IntMap.Strict as Map
3030import Control.Monad.Trans.Control (liftWith, restoreT)
3131import Control.Monad.Morph (hoist)
3232import Data.List as DL
33−import PGQueue.Web as Web
33+import OddJobs.Web as Web
3434import Data.Time.Convenience as Time
3535import qualified Data.Text as T
3636import Data.Ord (comparing, Down(..))
test/Try.hsnew file+28
@@ -0,0 +1,28 @@
1+{-# LANGUAGE FlexibleContexts #-}
2+module Try where
3+
4+import Hedgehog
5+import qualified Hedgehog.Gen as Gen
6+import qualified Hedgehog.Range as Range
7+import Control.Exception.Lifted
8+import Control.Concurrent.Async.Lifted
9+import Control.Monad
10+import Data.Pool as Pool
11+import Debug.Trace
12+import Control.Monad.IO.Unlift (liftIO)
13+import qualified System.Random as R
14+import Data.String (fromString)
15+
16+withRandomTable pool action = do
17+ tname <- liftIO ((("jobs_" <>) . fromString) <$> (replicateM 10 (R.randomRIO ('a', 'z'))))
18+ finally
19+ (Pool.withResource pool $ \conn -> (liftIO $ traceM "I will create the random table here") >> (action tname))
20+ (Pool.withResource pool $ \conn -> liftIO $ traceM "I will drop the random table here")
21+
22+myTest pool = property $ do
23+ randomData <- forAll $ Gen.list (Range.linear 1 100) (Gen.element [1, 2, 3])
24+ test $ withRandomTable pool $ \tname -> do
25+ withAsync
26+ (traceM "I will be a long-running background thread")
27+ (const $ traceM $ "hooray... I got the random table name " <> tname)
28+ True === True
test/Try2.hsnew file+62
@@ -0,0 +1,62 @@
1+module Try2 where
2+
3+-- import Control.Concurrent.Lifted
4+-- import Control.Concurrent.Async.Lifted
5+-- import Control.Exception.Lifted
6+import UnliftIO.Concurrent
7+import UnliftIO.Async
8+import UnliftIO.Exception
9+import Control.Concurrent.Async (AsyncCancelled(..))
10+import Debug.Trace
11+import Control.Monad
12+import Data.Functor
13+import Control.Monad.Reader
14+import Data.Maybe
15+
16+-- oneSec :: Int
17+-- oneSec = 1000000
18+
19+
20+-- main :: IO ()
21+-- main = finally
22+-- (withAsync
23+-- (catch runMonitoringThread (\AsyncCancelled -> print "---- delivered in main"))
24+-- (const $ threadDelay $ oneSec * 5))
25+-- (print "finally executed")
26+
27+
28+-- myPrint = liftIO . print
29+
30+-- runMonitoringThread :: IO ()
31+-- runMonitoringThread = do
32+-- print "something random"
33+-- runReaderT runMonitoringThread2 10
34+
35+-- runMonitoringThread2 :: ReaderT Int IO ()
36+-- runMonitoringThread2 = do
37+-- x <- ask
38+-- myPrint $ "==== got the number " <> show x
39+-- runMonitoringThread_ Nothing Nothing
40+-- where
41+-- runMonitoringThread_ mThread1 mThread2= do
42+-- thread1 <- maybe (async task1) pure mThread1
43+-- thread2 <- maybe (async task2) pure mThread2
44+-- -- catch (myWait thread1 thread2) (\AsyncCancelled -> myPrint "signal delivered in myWait" >> cancel thread1 >> cancel thread2)
45+-- finally
46+-- (myWait thread1 thread2)
47+-- (myPrint "FINALLY" >> cancel thread1 >> cancel thread2)
48+
49+-- task1 = forever $ do
50+-- myPrint "thread a is running"
51+-- threadDelay oneSec
52+
53+-- task2 = forever $ do
54+-- myPrint "thread 2 is running"
55+-- threadDelay (oneSec * 2)
56+
57+-- myWait :: Async () -> Async () -> ReaderT Int IO ()
58+-- myWait thread1 thread2 = do
59+-- waitEitherCatch thread1 thread2 >>= \case
60+-- Left _ -> runMonitoringThread_ Nothing (Just thread2)
61+-- Right _ -> runMonitoringThread_ (Just thread1) Nothing
62+-- myPrint "this should never get executed"