Categorygithub.com/Av1shay/timers-scheduler-demo
repositorypackage
0.0.0-20230520182356-dbb7e4ec6d9e
Repository: https://github.com/av1shay/timers-scheduler-demo.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Timers Scheduler demo

Demo project that exposes API to create timers which invoke a URL after specified time passed. Using mysql DB with ent as ORM, and rabbitMQ as queue to proccess the messages.

It works by storing each time due date in DB, and run local cron every second that checks which timers should run now, and adds them to a queue for processing.

Run locally

docker-compose up -d
go run main.go

Usage

Create a new timer by issuing a POST request to localhost:8081/timers.

We have a dummy endpoint /test-webhook to simulate successful webhook call. For example if we want to add a new timer that will call the dummy URL after 2 minutes and 10 seconds:

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"hours":0,"minutes":2,"seconds":10,"url":"http://localhost:8081/test-webhook"}' \
  http://localhost:8081/timers

Success response return the id of the timer:

{
  "id": 5
}

Get the time left of a specific timer by issuing a GET request to localhost:8081/timers/:id, success response will contain the id and time left in seconds, for example:

curl http://localhost:8081/timers/5

Success response:

{
  "id": 5,
  "time_left": 246
}

Run tests

make tests

Change default config

You can change default config by creating .env file and set the values from .env.example

PORT=
QUEUE_NAME=
MYSQL_CONNECTION=
RABBITMQ_CONNECTION=