10000 GitHub - bwaklog/saturn: Saturn is an in-memory timer daemon that waits for sometime and sends an HTTP request when it's done
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Saturn is an in-memory timer daemon that waits for sometime and sends an HTTP request when it's done

License

Notifications You must be signed in to change notification settings

bwaklog/saturn

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Saturn - a Timer Daemon

Saturn is an in-memory timer daemon built on golang's time.AfterFunc. It fires an event to a given webhook after a specified duration, returning user-assigned content.

Usage

# if you have a pre-defined webhook URL:
$ go run main.go --webhook_url="http://<YOUR API ENDPOINT HERE>"
# if you don't, and just want to see how it works
$ go run main.go 

Submit a POST request of the following format:

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "event_id": "first", "timeout_seconds": 10, "emit": "lol" }' \
  http://localhost:3000/register

And recieve a POST request on a specified webhook URL, after 10 seconds, with the following format:

{"event_id": "first", "message": "lol", "time_initiated": ""}

Alternatively, you can cancel a timeout with the following -

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "event_id": "first" }' \
  http://localhost:3000/cancel

You can request for the remaining time with the following request format:

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "event_id": "first" }' \
  http://localhost:3000/remaining

You can extend the timer for an event with the format:

curl --header "Content-Type: application/json" \
  --request 
52DC
POST \
  --data '{ "event_id": "first", "timeout_seconds": 10, "emit": "lol" }' \
  http://localhost:3000/extend

Once the timer is finished, we recieve a POST request in the similar format as mentioned before


## Design

Given that `time.AfterFunc` waits in its own goroutine until the time elapses, we need to give each call its own goroutine. This is mostly okay because all of these goroutines will be sleeping for the majority of their lifespan, and can thus be happily un-scheduled. 

About

Saturn is an in-memory timer daemon that waits for sometime and sends an HTTP request when it's done

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%
0