[bee] fix tests, update readme

parent d783198e
Pipeline #6814 failed with stages
in 3 minutes and 49 seconds
# Haskell-bee
![bee on a honeycomb](img/bee-wiki.jpg)
![bee on a honeycomb. Credits: https://en.wikipedia.org/wiki/Honey_bee#/media/File:Western_honey_bee_on_a_honeycomb.jpg](img/bee-wiki.jpg)
This is a library for implementing asynchronous workers which can fetch jobs from a (configurable) broker.
......@@ -36,3 +36,37 @@ This contains information such as:
- after job finishes
- after timeout occurred
- after job error
## Other work
[Haskell Job Queues: An Ultimate Guide (2020)](https://www.haskelltutorials.com/odd-jobs/haskell-job-queues-ultimate-guide.html)
- [hasql-queue](https://hackage.haskell.org/package/hasql-queue) This
implements a custom PostgreSQL schema. On top of that it proviedes
some simple strategies for running tasks.
- [immortal-queue](https://hackage.haskell.org/package/immortal-queue)
This is a library that you can use to build an asynchronous worker
pool. The `Broker` can be configurable.
- [job](https://hackage.haskell.org/package/job-0.1.1/docs/Job.html)
Recent addition with Broker, Worker, job metadata. Supports
retrying, re-nicing.
- [odd-jobs](https://hackage.haskell.org/package/odd-jobs)
PostgreSQL-backed, has an admin UI, seems mature.
### Brokers
These libraries implement mostly the queueing mechanism only, without
any job metadata structure like in haskell-bee. They fall into the
`Broker` category of haskell-bee.
- [postgresql-simple-queue](https://hackage.haskell.org/package/postgresql-simple-queue)
(it uses a custom queueing mechanism; it is more like a `Broker` in haskell-bee)
- [stm-queue](https://hackage.haskell.org/package/stm-queue) (in-memory only)
- [mongodb-queue](https://hackage.haskell.org/package/mongodb-queue)
(again, similar to our `Broker`)
- [amazonka-sqs](https://hackage.haskell.org/package/amazonka-sqs)
(again, a `Broker`, based on Amazon SQS. Might be worth integrating
this in the future)
- [redis-job-queue](https://hackage.haskell.org/package/redis-job-queue)
(worth investigating the sorted set approach)
- [poolboy](https://hackage.haskell.org/package/poolboy) (in-memory only)
index-state: 2023-12-10T10:34:46Z
with-compiler: ghc-9.4.7
with-compiler: ghc-9.4.8
packages:
./
......
......@@ -79,7 +79,7 @@ library
-- Other library packages from which modules are imported.
build-depends: base ^>=4.17.2.0
, aeson >= 1.4 && < 2.3
, aeson >= 2.1 && < 2.3
, bytestring >= 0.11 && < 0.13
, containers >= 0.6.7 && < 0.8
, haskell-pgmq >= 0.1.0.0 && < 0.2
......@@ -115,7 +115,7 @@ executable simple-worker
import: warnings
build-depends: base ^>=4.17.2.0
, aeson >= 1.4 && < 2.3
, aeson >= 2.1 && < 2.3
, haskell-pgmq >= 0.1.0.0 && < 0.2
, mtl >= 2.2 && < 2.4
, postgresql-simple >= 0.6 && < 0.8
......@@ -147,7 +147,7 @@ test-suite test-unit
type: exitcode-stdio-1.0
build-depends: base ^>=4.17.2.0
, aeson >= 1.4 && < 2.3
, aeson >= 2.1 && < 2.3
, tasty >= 1.5 && < 1.6
, tasty-hunit >= 0.10 && < 0.11
, tasty-quickcheck >= 0.10 && < 0.12
......@@ -183,7 +183,7 @@ test-suite test-integration
, Test.Integration.Worker
build-depends: base ^>=4.17.2.0
, aeson >= 1.4 && < 2.3
, aeson >= 2.1 && < 2.3
, containers >= 0.6 && < 0.8
, hedis >= 0.15.2 && < 0.16
, hspec >= 2.11 && < 3
......@@ -204,6 +204,7 @@ test-suite test-integration
default-language: Haskell2010
default-extensions:
DeriveGeneric
DuplicateRecordFields
GeneralizedNewtypeDeriving
ImportQualifiedPost
......
......@@ -29,10 +29,11 @@ import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TVar (readTVarIO, newTVarIO, TVar, modifyTVar)
import Control.Exception (bracket, Exception, throwIO)
import Control.Monad (void)
import Data.Aeson (ToJSON(..), FromJSON(..), object, (.=), (.:), withObject)
import Data.Aeson (ToJSON, FromJSON)
import Data.Map.Strict qualified as Map
import Data.Maybe (fromJust, isJust)
import Data.Set qualified as Set
import GHC.Generics (Generic)
import Test.Hspec
import Test.Integration.Utils (defaultPGMQVt, getPSQLEnvConnectInfo, getRedisEnvConnectInfo, randomQueueName, waitUntil, waitUntilTVarEq, waitUntilTVarPred, waitUntil, waitUntilQueueEmpty)
......@@ -57,23 +58,25 @@ data Message =
Message { text :: String }
| Error
| Timeout { delay :: Int }
deriving (Show, Eq, Ord)
instance ToJSON Message where
toJSON (Message { text }) = toJSON $ object [ "type" .= ("Message" :: String), "text" .= text ]
toJSON Error = toJSON $ object [ "type" .= ("Error" :: String) ]
toJSON (Timeout { delay }) = toJSON $ object [ "type" .= ("Timeout" :: String), "delay" .= delay ]
instance FromJSON Message where
parseJSON = withObject "Message" $ \o -> do
type_ <- o .: "type"
case type_ of
"Message" -> do
text <- o .: "text"
pure $ Message { text }
"Error" -> pure Error
"Timeout" -> do
delay <- o .: "delay"
pure $ Timeout { delay }
_ -> fail $ "Unknown type " <> type_
deriving (Show, Eq, Ord, Generic)
instance ToJSON Message
instance FromJSON Message
-- instance ToJSON Message where
-- toJSON (Message { text }) = toJSON $ object [ "type" .= ("Message" :: String), "text" .= text ]
-- toJSON Error = toJSON $ object [ "type" .= ("Error" :: String) ]
-- toJSON (Timeout { delay }) = toJSON $ object [ "type" .= ("Timeout" :: String), "delay" .= delay ]
-- instance FromJSON Message where
-- parseJSON = withObject "Message" $ \o -> do
-- type_ <- o .: "type"
-- case type_ of
-- "Message" -> do
-- text <- o .: "text"
-- pure $ Message { text }
-- "Error" -> pure Error
-- "Timeout" -> do
-- delay <- o .: "delay"
-- pure $ Timeout { delay }
-- _ -> fail $ "Unknown type " <> type_
-- | We will handle job events from the worker to track what and how
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment