Skip to content

Repository files navigation

[POC] Postgres trigger program

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

# 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

How to run with dotnet CLI

# 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

Useful links

About

POC for using Postgres to trigger a program execution leveraging F#'s native MailboxProcessor

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages