[bee] fix tests, update readme

parent d783198e
Pipeline #6814 failed with stages
in 3 minutes and 49 seconds
# Haskell-bee # 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. 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: ...@@ -36,3 +36,37 @@ This contains information such as:
- after job finishes - after job finishes
- after timeout occurred - after timeout occurred
- after job error - 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 index-state: 2023-12-10T10:34:46Z
with-compiler: ghc-9.4.7 with-compiler: ghc-9.4.8
packages: packages:
./ ./
......
...@@ -79,7 +79,7 @@ library ...@@ -79,7 +79,7 @@ library
-- Other library packages from which modules are imported. -- Other library packages from which modules are imported.
build-depends: base ^>=4.17.2.0 build-depends: base ^>=4.17.2.0
, aeson >= 1.4 && < 2.3 , aeson >= 2.1 && < 2.3
, bytestring >= 0.11 && < 0.13 , bytestring >= 0.11 && < 0.13
, containers >= 0.6.7 && < 0.8 , containers >= 0.6.7 && < 0.8
, haskell-pgmq >= 0.1.0.0 && < 0.2 , haskell-pgmq >= 0.1.0.0 && < 0.2
...@@ -115,7 +115,7 @@ executable simple-worker ...@@ -115,7 +115,7 @@ executable simple-worker
import: warnings import: warnings
build-depends: base ^>=4.17.2.0 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 , haskell-pgmq >= 0.1.0.0 && < 0.2
, mtl >= 2.2 && < 2.4 , mtl >= 2.2 && < 2.4
, postgresql-simple >= 0.6 && < 0.8 , postgresql-simple >= 0.6 && < 0.8
...@@ -147,7 +147,7 @@ test-suite test-unit ...@@ -147,7 +147,7 @@ test-suite test-unit
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
build-depends: base ^>=4.17.2.0 build-depends: base ^>=4.17.2.0
, aeson >= 1.4 && < 2.3 , aeson >= 2.1 && < 2.3
, tasty >= 1.5 && < 1.6 , tasty >= 1.5 && < 1.6
, tasty-hunit >= 0.10 && < 0.11 , tasty-hunit >= 0.10 && < 0.11
, tasty-quickcheck >= 0.10 && < 0.12 , tasty-quickcheck >= 0.10 && < 0.12
...@@ -183,7 +183,7 @@ test-suite test-integration ...@@ -183,7 +183,7 @@ test-suite test-integration
, Test.Integration.Worker , Test.Integration.Worker
build-depends: base ^>=4.17.2.0 build-depends: base ^>=4.17.2.0
, aeson >= 1.4 && < 2.3 , aeson >= 2.1 && < 2.3
, containers >= 0.6 && < 0.8 , containers >= 0.6 && < 0.8
, hedis >= 0.15.2 && < 0.16 , hedis >= 0.15.2 && < 0.16
, hspec >= 2.11 && < 3 , hspec >= 2.11 && < 3
...@@ -204,6 +204,7 @@ test-suite test-integration ...@@ -204,6 +204,7 @@ test-suite test-integration
default-language: Haskell2010 default-language: Haskell2010
default-extensions: default-extensions:
DeriveGeneric
DuplicateRecordFields DuplicateRecordFields
GeneralizedNewtypeDeriving GeneralizedNewtypeDeriving
ImportQualifiedPost ImportQualifiedPost
......
...@@ -29,10 +29,11 @@ import Control.Concurrent.STM (atomically) ...@@ -29,10 +29,11 @@ import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TVar (readTVarIO, newTVarIO, TVar, modifyTVar) import Control.Concurrent.STM.TVar (readTVarIO, newTVarIO, TVar, modifyTVar)
import Control.Exception (bracket, Exception, throwIO) import Control.Exception (bracket, Exception, throwIO)
import Control.Monad (void) 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.Map.Strict qualified as Map
import Data.Maybe (fromJust, isJust) import Data.Maybe (fromJust, isJust)
import Data.Set qualified as Set import Data.Set qualified as Set
import GHC.Generics (Generic)
import Test.Hspec import Test.Hspec
import Test.Integration.Utils (defaultPGMQVt, getPSQLEnvConnectInfo, getRedisEnvConnectInfo, randomQueueName, waitUntil, waitUntilTVarEq, waitUntilTVarPred, waitUntil, waitUntilQueueEmpty) import Test.Integration.Utils (defaultPGMQVt, getPSQLEnvConnectInfo, getRedisEnvConnectInfo, randomQueueName, waitUntil, waitUntilTVarEq, waitUntilTVarPred, waitUntil, waitUntilQueueEmpty)
...@@ -57,23 +58,25 @@ data Message = ...@@ -57,23 +58,25 @@ data Message =
Message { text :: String } Message { text :: String }
| Error | Error
| Timeout { delay :: Int } | Timeout { delay :: Int }
deriving (Show, Eq, Ord) deriving (Show, Eq, Ord, Generic)
instance ToJSON Message where instance ToJSON Message
toJSON (Message { text }) = toJSON $ object [ "type" .= ("Message" :: String), "text" .= text ] instance FromJSON Message
toJSON Error = toJSON $ object [ "type" .= ("Error" :: String) ] -- instance ToJSON Message where
toJSON (Timeout { delay }) = toJSON $ object [ "type" .= ("Timeout" :: String), "delay" .= delay ] -- toJSON (Message { text }) = toJSON $ object [ "type" .= ("Message" :: String), "text" .= text ]
instance FromJSON Message where -- toJSON Error = toJSON $ object [ "type" .= ("Error" :: String) ]
parseJSON = withObject "Message" $ \o -> do -- toJSON (Timeout { delay }) = toJSON $ object [ "type" .= ("Timeout" :: String), "delay" .= delay ]
type_ <- o .: "type" -- instance FromJSON Message where
case type_ of -- parseJSON = withObject "Message" $ \o -> do
"Message" -> do -- type_ <- o .: "type"
text <- o .: "text" -- case type_ of
pure $ Message { text } -- "Message" -> do
"Error" -> pure Error -- text <- o .: "text"
"Timeout" -> do -- pure $ Message { text }
delay <- o .: "delay" -- "Error" -> pure Error
pure $ Timeout { delay } -- "Timeout" -> do
_ -> fail $ "Unknown type " <> type_ -- delay <- o .: "delay"
-- pure $ Timeout { delay }
-- _ -> fail $ "Unknown type " <> type_
-- | We will handle job events from the worker to track what and how -- | 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