[demo] some fixes, README added

parent d2931dc6
Pipeline #7225 failed with stages
in 14 minutes and 34 seconds
# haskell-bee demo
## DB setup
This is a simple demo of pgmq-based workers.
First, you need a postgresql database:
```shell
podman run --rm -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres postgres
```
Next, you can configure postgres access via an env variable:
```shell
export POSTGRES_CONN="host=localhost port=5432 dbname=postgres user=postgres password=postgres"
```
## Command-line
To run the command-line and see available options:
```shell
cabal v2-run demo -- -h
```
You need to spawn the worker first:
```shell
cabal v2-run demo -- worker
```
Now you can send tasks to the worker (from another terminal):
```shell
cabal v2-run demo -- echo "hello"
cabal v2-run demo -- error "oops!"
cabal v2-run demo -- wait 10
cabal v2-run demo -- quit
```
## About killing with `Ctrl-C`
`haskell-bee` implements possibility of a graceful shutdown of the worker.
Depending on the `resendWhenWorkerKilled` property in the task
metadata, the currently running task will be either killed and
discarded or killed and resent to the broker.
One often kills command-line programs with `Ctrl-C`. Hence, a small
wrapper is needed around `initWorker` to support such graceful
shutdown:
```haskell
initWorker "default" _ga_queue $ \a _state -> do
let tid = asyncThreadId a
_ <- installHandler keyboardSignal (Catch (throwTo tid W.KillWorkerSafely)) Nothing
wait a
```
...@@ -20,7 +20,10 @@ data Program = ...@@ -20,7 +20,10 @@ data Program =
programParser :: ParserInfo Program programParser :: ParserInfo Program
programParser = info programParser = info
( ( Program <$> global <*> commandParser ) <**> helper ) mempty ( ( Program <$> global <*> commandParser ) <**> helper )
( fullDesc
<> header "haskell-bee demo"
<> progDesc "Simple demonstration of worker capabilities" )
data GlobalArgs = data GlobalArgs =
GlobalArgs { _ga_queue :: B.Queue } GlobalArgs { _ga_queue :: B.Queue }
...@@ -45,14 +48,14 @@ data Command ...@@ -45,14 +48,14 @@ data Command
commandParser :: Parser Command commandParser :: Parser Command
commandParser = subparser commandParser = subparser
( command "worker" (info (worker <**> helper) mempty ) ( command "worker" (info (worker <**> helper) (progDesc "run worker") )
<> command "queue-size" (info (queueSize <**> helper) mempty ) <> command "queue-size" (info (queueSize <**> helper) (progDesc "show queue size") )
-- tasks -- tasks
<> command "echo" (info (echo <**> helper) mempty ) <> command "echo" (info (echo <**> helper) (progDesc "echo task") )
<> command "error" (info (error' <**> helper) mempty ) <> command "error" (info (error' <**> helper) (progDesc "error task") )
<> command "quit" (info (quit <**> helper) mempty ) <> command "quit" (info (quit <**> helper) (progDesc "quit task") )
<> command "wait" (info (wait <**> helper) mempty ) <> command "wait" (info (wait <**> helper) (progDesc "wait task") )
) )
data WorkerArgs = data WorkerArgs =
......
...@@ -2,9 +2,10 @@ with-compiler: ghc-9.4.8 ...@@ -2,9 +2,10 @@ with-compiler: ghc-9.4.8
packages: packages:
./ ./
../ ../haskell-bee
../haskell-bee-pgmq
source-repository-package source-repository-package
type: git type: git
location: https://gitlab.iscpif.fr/gargantext/haskell-pgmq location: https://gitlab.iscpif.fr/gargantext/haskell-pgmq
tag: 0591a643d8ba1776af4fac56c1e4ff5fc3e98bb3 tag: 1dd92f0aa8e9f8096064e5656c336e562680f4e3
...@@ -65,6 +65,7 @@ library ...@@ -65,6 +65,7 @@ library
, aeson >= 2.1 && < 2.3 , aeson >= 2.1 && < 2.3
, async >= 2.2 && < 2.3 , async >= 2.2 && < 2.3
, haskell-bee , haskell-bee
, haskell-bee-pgmq
, postgresql-simple >= 0.7.0 && < 0.8 , postgresql-simple >= 0.7.0 && < 0.8
, safe-exceptions >= 0.1.7 && < 0.2 , safe-exceptions >= 0.1.7 && < 0.2
, text >= 2.0 && < 2.2 , text >= 2.0 && < 2.2
......
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