!NOTE
: take the next steps only once, but I will put them in both componentβs README
for better convenience.
In order to run the docker servers using docker compose
do the following steps:
- Open your terminal and paste:
mkdir restaurant-simulator
I will add the links after I configure everything.
cd restaurant-simulator
touch docker-compose.yml
- Paste the following into the
docker-compose.yml
file.
version: '3'
services:
kitchen_1:
build: ./kitchen-server
ports:
- "3111:3111"
environment:
- USING_DOCKER_COMPOSE=1
- RESTAURANT_ID=1
depends_on:
- restaurant-aggregator
kitchen_2:
build: ./kitchen-server
ports:
- "3222:3222"
environment:
- USING_DOCKER_COMPOSE=1
- RESTAURANT_ID=2
depends_on:
- restaurant-aggregator
# dining-hall:
# build: ./dining-hall-server
# ports:
# - "8080:8080"
# environment:
# - USING_DOCKER_COMPOSE=1
restaurant-aggregator:
build: ./restaurant-aggregator-server
ports:
- "7777:7777"
environment:
- USING_DOCKER_COMPOSE=1
client-server:
build: ./client-server
ports:
- "3333:3333"
environment:
- USING_DOCKER_COMPOSE=1
depends_on:
- restaurant-aggregator
- kitchen_1
- kitchen_2
- Start the Docker service:
sudo systemctl start docker
- Then run the command:
sudo docker compose up --build
- Create a folder
restaurant-simulator
. - Open a Terminal/Git Bash in that folder.
- Paste the following line by line:
I will add the links after I configure everything.
- Create a new file
docker-compose.yml
in therestaurant-simulator
folder. - Add the following to the previously created file:
version: '3'
services:
kitchen_1:
build: ./kitchen-server
ports:
- "3111:3111"
environment:
- USING_DOCKER_COMPOSE=1
- RESTAURANT_ID=1
depends_on:
- restaurant-aggregator
kitchen_2:
build: ./kitchen-server
ports:
- "3222:3222"
environment:
- USING_DOCKER_COMPOSE=1
- RESTAURANT_ID=2
depends_on:
- restaurant-aggregator
# dining-hall:
# build: ./dining-hall-server
# ports:
# - "8080:8080"
# environment:
# - USING_DOCKER_COMPOSE=1
restaurant-aggregator:
build: ./restaurant-aggregator-server
ports:
- "7777:7777"
environment:
- USING_DOCKER_COMPOSE=1
client-server:
build: ./client-server
ports:
- "3333:3333"
environment:
- USING_DOCKER_COMPOSE=1
depends_on:
- restaurant-aggregator
- kitchen_1
- kitchen_2
- Make sure to have
Docker Desktop
started. - Run
docker-compose up --build
The Kitchen
has a finite order list
. This order list
is shared across all kitchen
instances. All orders which kitchen receives have to be added to a single instance of order-list
.
Main work unit of the Kitchen
are cooks. Their job is to take the order
and βprepareβ the menu item(s) from it, and return the orders as soon and with as little idle time as possible. Kitchen can prepare foods from different orders and it is not mandatory that one cook have to prepare entire order. Order is considered to be prepared when all foods from order list are prepared.
Each cook has the following characteristics:
- rank: which defines the complexity of the food that they can prepare (one caveat is that a cook can only take orders which his current rank or one rank lower that his current one):
- Line Cook ( rank = 1 )
- Saucier ( rank = 2 )
- Executive Chef (Chef de Cuisine) ( rank = 3 )
- proficiency: it indicates on how may dishes he can work at once. It varies between 1 and 4 (and to follow a bit of logic, the higher the rank of a cook the higher is the probability that he can work on more dishes at the same time).
- name
- catch phrase
So a cook could have the following definition:
{
"rank": 3,
"proficiency": 3,
"name": "Gordon Ramsay",
"catch-phrase": "Hey, panini head, are you listening to me?"
}
Register each Restaurant to the Aggregator.
_ = requests.post(
url=f'http://restaurant-aggregator:7777/register',
json={
'restaurant_id': RESTAURANT_ID,
'name': RESTAURANT_CFG[RESTAURANT_ID]['name'],
'address': f'http://{RESTAURANT_CFG[RESTAURANT_ID]["HOST_NAME"]}:{RESTAURANT_CFG[RESTAURANT_ID]["DINING_HALL_PORT"]}',
'menu_items': len(RESTAURANT_CFG[RESTAURANT_ID]['menu']),
'menu': RESTAURANT_CFG[RESTAURANT_ID]['menu']
}
)
The Kitchen
consists of order list
, cooks
and cooking apparatus
. The order list should be a single instance which holds all orders received from Dinning Hall .
The Kitchen
should handle HTTP (POST) requests of receiving orders from the Dinning Hall and add received order to order list . For all received orders kitchen have to register time it was received and time is was totally prepared. Cooking time
should be added to order before sending it back to Dinning Hall
.
Cooks
should be an object instances which run their logic of preparing foods on separate threads , one thread per cook .
Your task is to design a mechanism which will prepare orders by using cooks
as work unit. It is up to you to decide how orders will be managed and how foods will be assigned to cooks in order to be prepared. Your main goal is to reduce preparation time of each order.
The kitchen
has a limited number of cooking apparatus
and in our case we will use only stoves and ovens. Cooking apparatus
should be object instances which work independently and in parallel. Cooking apparatus are sharable resources across all cooks and you have to carefully use them.
Number and types of cooks
and cooking apparatus
should be configurable.
When order
is prepared, meaning that all foods from order are prepared. Kitchen
should perform HTTP (POST) request with prepared order details to Dinning Hall
in that way returning prepared order to be served to the table.
If you have any question, please contact me through email: [email protected]
.