In this exercise, you will implement a bash program which reserves seats for a digital ticketing solution, using Redis database. In simple words: whenever a customer wants to book a seat for an event (e.g. for a theatre show), your bash program will lock the selected seats for a period of time, such that other customers won't be able to book for those seats.
- Open our shared git repo in PyCharm (or clone if you didn't do it yet: git -> clone...)
- Make sure you are on Git branch
main
! If the bottom right bar in your PyCharm looks different from , click on it, hover themain
branch and click Checkout. - On branch
main
, pull the repository to get an up-to-date version of the repository. - From PyCharm button right bar, click the button to display Git branches in the repo. Choose + New branch to create your own git branch by(Git branches will be discussed later).
- In the opened window, give your branch a name according to the following template:
bash_ex5/<alias>
While changing <alias>
to your nickname. e.g. bash_ex5/alonit
. The branch name must start with bash_ex5/
.
- Install Docker on your Ubuntu if needed.
In order to book a seat, first this seat must be locked by a customer. The lock is valid for 600 seconds. Then the customer that locked the seat can book it during the given locking time. Once seat was booked, the lock is being released and this seat cannot be locked anymore.
- Run Redis in a Docker container by:
Your Redis server will be accessible in localhost:6378
docker run --rm -p 6378:6379 --name some-redis redis
- You are given a solution skeleton in
ex5_optional/seat.sh
. Your goal is to implement the functionslock
,release
andbook
. Read the documentation attached at the top of each function. - Here is an example of how your program should behave:
>> ./seat.sh lock "Oedipus_the_King" "Andreas" 56 Seat was locked >> ./seat.sh lock "Oedipus_the_King" "Marios" 56 This seat is currently locked by other customer, try again later >> ./seat.sh release "Oedipus_the_King" "Andreas" 56 The seat was released >> ./seat.sh book "Oedipus_the_King" "Marios" 56 Booking failed, please lock the seat before >> ./seat.sh lock "Oedipus_the_King" "Marios" 56 The seat was locked >> ./seat.sh book "Oedipus_the_King" "Marios" 56 Successfully booked this seat! >> ./seat.sh lock "Oedipus_the_King" "Andreas" 56 Locking failed, seat is already booked
Commit and push ex5_optional/seat.sh
file only. Make sure your solution passing the pre-submit tests.
Feel free to ask any questions!