https://github.com/64j0/poc--postgres-trigger-program
POC for using Postgres to trigger a program execution leveraging F#'s native MailboxProcessor
https://github.com/64j0/poc--postgres-trigger-program
api distributed-systems fsharp giraffe mailbox-processor postgres
Last synced: about 1 month ago
JSON representation
POC for using Postgres to trigger a program execution leveraging F#'s native MailboxProcessor
- Host: GitHub
- URL: https://github.com/64j0/poc--postgres-trigger-program
- Owner: 64J0
- License: mit
- Created: 2024-12-20T23:02:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-10T22:44:33.000Z (about 1 year ago)
- Last Synced: 2025-06-10T23:32:30.530Z (about 1 year ago)
- Topics: api, distributed-systems, fsharp, giraffe, mailbox-processor, postgres
- Language: F#
- Homepage:
- Size: 98.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+TITLE: [POC] Postgres trigger program
#+DATE: [2024-12-26 qui]
The idea of this POC project is to create a multi-service application composed
of:
- 1. An HTTP Rest API to interact with the user to set scripts that are going to
be run in the background,
- 2. A Postgres database to store the data (application's source of truth) that
is also responsible for communicating the background application about new
script execution requests,
- 3. A background application leveraging a MailboxProcessor that is notified by
the database whenever a new ~program_execution~ entity is created and it's
used to run the specified program, collect its output and update the database
accordingly.
Other than this, when using the API the user will be able to:
- [X] Register new scripts;
- [X] List scripts that are already registered;
- [ ] Get the script execution results.
** How to run with containers
#+BEGIN_SRC bash :tangle no
# start the containerized project
make compose-up
# start playing with the API and check the logs from the manager process
curl \
-d '{"programName":"placeholder_001"}' \
-H "Content-Type: application/json" \
-X POST \
http://localhost:5000/api/program
curl http://localhost:5000/api/programs
# upload the script (change the necessary details at the following command):
curl --request PATCH \
--url http://localhost:5000/api/program/PROGRAM_ID_GUID \
--header 'Content-Type: multipart/form-data' \
--form script=@/YOUR_LOCAL_PATH/samples/wait.fsx
curl \
-d '{"programInput":"100"}' \
-H "Content-Type: application/json" \
-X POST \
http://localhost:5000/api/execution/PROGRAM_ID_GUID
# check the database and the container logs
#+END_SRC
** How to run with dotnet CLI
#+BEGIN_SRC bash :tangle no
# 1st shell
#
# start the database container with
docker compose up -d postgres
# if you need to restart it use
#
# docker compose down
# docker compose up -d postgres
#
# check the logs with
#
# docker container logs -f postgres_container
# Start the API with
dotnet run --define:DEBUG --project api/
# ===============================================
# 2nd shell
#
# start the manager process
dotnet run --define:DEBUG --project manager/
# ===============================================
# 3rd shell
#
# start playing with the API and check the logs from the manager process
curl \
-d '{"programName":"placeholder_001"}' \
-H "Content-Type: application/json" \
-X POST \
http://localhost:5000/api/program
curl http://localhost:5000/api/programs
# upload the script (change the necessary details at the following command):
curl --request PATCH \
--url http://localhost:5000/api/program/PROGRAM_ID_GUID \
--header 'Content-Type: multipart/form-data' \
--form script=@/YOUR_LOCAL_PATH/samples/get_date.fsx
curl \
-d '{"programInput":"1 2 3"}' \
-H "Content-Type: application/json" \
-X POST \
http://localhost:5000/api/execution/PROGRAM_ID_GUID
curl http://localhost:5000/api/executions
#+END_SRC
** Useful links
- *POSTGRES:*
- https://www.postgresql.org/docs/current/sql-notify.html
- https://www.npgsql.org/doc/wait.html
- https://tedeh.net/publishing-rabbitmq-messages-from-postgresql/
- *F#:*
- https://thesharperdev.com/fsharps-mailboxprocessor/
- https://en.wikibooks.org/wiki/F_Sharp_Programming/MailboxProcessor
- https://fsharpforfunandprofit.com/posts/concurrency-actor-model/