Coffee Machine

This coffee machine is taken form the “12-factor-workshop” by NSD - Norsk Senter for Forskningsdata AS, licensed under CC-BY 3.0.

Start a coffee job

POST /start-job
  • Payload
{
  "product": "COFFEE",
  "jobId": "00000000-BBBB-0000-BBBB-000000000000"
}

The jobId is optional and will be auto-generated by the Coffee Machine if absent.

  • Response

If the Coffee Machine is able to accept jobs, it takes it.

{
  "jobId": "00000000-BBBB-BBBB-BBBB-000000000000",
  "product": "COFFEE",
  "jobStarted": "2019-08-01T00:00:01.000Z",
  "jobReady": "2019-08-01T00:00:31.000Z"
}

If the Coffee Machine is unable to take jobs, they are rejected.

Code Content
503 {"message: "Machine busy!"}

Retrieve a job

GET /retrieve-job/:jobId

The coffee can only be retrieved if it is ready (jobRead is in the past) and not yet retrieved (jobRetrieved empty).

  • If the conditions are not met, the answer is
Code Content
503 {"message: "Job not ready"}
404 {"message: "Job unknown"}
410 {"message: "Job already retrieved"}
  • If the conditions are met, the jobRetrieved is updated and the coffee returned.
{
  "jobId": "00000000-BBBB-BBBB-BBBB-000000000000",
  "product": "COFFEE",
  "jobStarted": "2019-08-01T00:00:01.000Z",
  "jobReady": "2019-08-01T00:00:31.000Z",
  "jobRetrieved": "2019-08-01T00:00:32.000Z",
}

Prometheus metrics

GET /metrics
  • Response
# HELP coffee_machine_status The system status 0=idle,1=brewing,2=blocked or other.
# TYPE coffee_machine_status gauge
coffee_machine_status 0

Get an overview of the Coffee Machine history

GET /job-history
  • Response

A JSON array of all jobs given to and processed by the machine, irrespective of state and without any pagination.

[
  {
    "jobId": "00000000-2222-2222-2222-000000000000",
    "product": "KAKAO",
    "jobStarted": "2019-07-31T01:00:01.000Z",
    "jobReady": "2019-07-31T01:00:31.000Z",
    "jobRetrieved": "2019-07-31T01:00:32.000Z"
  },
  {
    "jobId": "00000000-1111-1111-1111-000000000000",
    "product": "KAKAO",
    "jobStarted": "2019-07-31T01:01:01.000Z",
    "jobReady": "2019-07-31T01:01:31.000Z",
    "jobRetrieved": ""
  }
]