Exploring the actor model, BEAM, OTP and Supervision tree.
gen_thumbnail is a set of two applications that create thumbnails (25%, 50% and 200% version) for a given image.
The thumbnail_http project exposes a simple REST API and is based on the awesome Plug specification.
The thumbnail_server project has all the logic for thumbnails creation: a GenServer thumbnail_receptor:
- Receives the query
- Starts an Agent (i.e
thumbnail_store) that stores all the paths to the differents thumbnails of the query - Spawn four Tasks (i.e
thumbnail_worker) that create the different thumbnails. Each Task uses a Port to launch the linux commandconvertfor the creation of the thumbnail.
iex -S mix
The application listens on the 8080port for the requests.
curl -X POST \
http://localhost:8080/thumbnails \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F image=@/home/salmane/Desktop/elixir.pngUpon success, gen_thumbnail responds with the following payloads:
{
"thumbnail_job_id": "0432d218-7641-11e9-b5be-000c293aa689"
}curl -X GET \
http://localhost:8080/thumbnails/0432d218-7641-11e9-b5be-000c293aa689 \The following response is returned:
{
"min_thumbnail_url": "/thumbnails/25_elixir.png",
"mid_thumbnail_url": "/thumbnails/50_elixir.png",
"max_thumbnail_url": "/thumbnails/200_elixir.png"
}curl -X GET \
http://localhost:8080/thumbnails/200_elixir.png \