A slightly over the top calculator that uses Docker to run your calculation on a random OS + language combination.
- Webserver that is responsible for
- Serving a UI
- Validating new calculations
- Adding calculations to the processing queue
- Mongodb that is responsible for
- Acting as a processing queue
- Acting as a datastore for completed calculations
- Acting as an error store for errored calculations
- One or more pollers that are responsible for
- running calculations
- telling Montodb about a completed calculation
Poller monitors Mongodb for new calculations and tells docker to run these calculations in a container, choosing a specific image and language to run the calculation with. Poller is also responsible for processing the output from the docker container, organizing the responses in Mongodb, and error handling
--debug
: Prints extra information. (TODO: Probably rename to --verbose/-v)
Setting up a poller environment can be tricky.
- Have a working docker environment.
- Clone this repo
- Run
make docker
- Run
go run poller/poller.go
Having a go compiler compiled to build linux binaries is required for building linux binaries. Under OS X, running brew uninstall go && brew install go --cross-compile-common
worked well. Then simply run make linux
for linux binaries and make
for local binaries.
Each calculator must adhere to the same API.
Accepts input as arguments to program in the form of
NUM OP NUM
NUM = number
OP = ["+", "-", "*", "/"]
Examples: 1.4 + 4; -5.11 / 8; 83242 * -0.2
Writes answer to STDOUT
We use Go as the main language in this project. It is the webserver (which also handles websocket connections) and it is the poller that acts as a message organizer. We use mgo as the MongoDB library.
MongoDB acts as both a datastore and a queue. One collection is used as the message queue. Calculations enter the "queue" and get picked up by the poller. They then sort themselves into the correct resulting collection either completed or error.
Docker is responsible for helping us run our calculations across different operating systems. We put our calculators in the docker image and run calculations through Docker. This is a somewhat odd use of Docker as Docker tends to be used as a running container that accepts input and gives output. This actually starts an image and runs the calculation on the running container. This will actually create a new container that needs to be cleaned up since we don't care about the resulting state of the image.
{
Calculation string // "1.21 / -32.33"
OS string // "Ubuntu 12.04 LTS"
Language string // "rb"
Id bson.ObjectId // # MongoID
Answer float64 // -0.0374265388184349
Instance string // "dockulator-ubuntu"
Time time.Time // # timestamp
Error string // "" #(hopefully)
Processing bool // true
}