README modified, haskell-bee-pgmq README added

parent 841b32fb
Pipeline #7219 canceled with stages
...@@ -24,15 +24,18 @@ The library so far contains 3 implementations for brokers: ...@@ -24,15 +24,18 @@ The library so far contains 3 implementations for brokers:
(c.f. https://redis.io/glossary/redis-queue/) (c.f. https://redis.io/glossary/redis-queue/)
- [**STM**](./haskell-bee-stm) - which uses the `STM`, could be useful for testing - [**STM**](./haskell-bee-stm) - which uses the `STM`, could be useful for testing
`pgmq` broker so far is assumed to be most stable and complete,
`redis` and `STM` are considered experimental.
The broker definition uses some more advanced GHC type extensions The broker definition uses some more advanced GHC type extensions
(in particular, [type families](https://wiki.haskell.org/GHC/Type_families)) (in particular, [type families](https://wiki.haskell.org/GHC/Type_families))
at the benefit of having one clear interface for what we expect from the broker. at the benefit of having one clear interface for what we expect from the broker.
### Worker ### Worker
The worker (defined in [`./src/Async/Worker.hs`]) is completely described by it's `State`. The worker (defined in [`./src/Async/Worker.hs`](./src/Async/Worker.hs)) is completely described by it's `State`.
This contains information such as: `State` contains information such as:
- broker instance - broker instance
- queue name (one worker is assumed to be assigned to a single queue. If you want more queues, just spawn more workers) - queue name (one worker is assumed to be assigned to a single queue. If you want more queues, just spawn more workers)
- actions to be performed on incoming data - actions to be performed on incoming data
...@@ -43,6 +46,7 @@ This contains information such as: ...@@ -43,6 +46,7 @@ This contains information such as:
- after timeout occurred - after timeout occurred
- after job error - after job error
This project doesn't provide worker management utilities.
## Testing ## Testing
......
# haskell-bee-pgmq
`pgmq` broker implementation for `haskell-bee`.
## Database initialization
Notice that upon broker initialization, this calls `PGMQ.initialize`
which tries very hard to create the pgmq schema for you.
If you also want to pre-create the database itself, with some given
user, you can try something like this:
```haskell
import Shelly qualified as SH
createDBIfNotExists :: Text -> Text -> IO ()
createDBIfNotExists connStr dbName = do
-- For the \gexec trick, see:
-- https://stackoverflow.com/questions/18389124/simulate-create-database-if-not-exists-for-postgresql
(_res, _ec) <- SH.shelly $ SH.silently $ SH.escaping False $ do
let sql = "\"SELECT 'CREATE DATABASE " <> dbName <> "' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '" <> dbName <> "')\\gexec\""
result <- SH.run "echo" [sql, "|", "psql", "-d", "\"" <> connStr <> "\""]
(result,) <$> SH.lastExitCode
return ()
```
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