-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicecream.py
41 lines (30 loc) · 1002 Bytes
/
icecream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import backoff
import collections
import random
class NetworkException(Exception):
pass
class Orders:
def __init__(self):
self.totalOrders = 0
self.orders = collections.defaultdict(list)
def add(self, date, order):
self.totalOrders += 1
self.orders[date].append(order)
def get_most_recent(self):
most_recent_key = sorted(self.orders.keys())[-1]
return self.orders[most_recent_key][0]
def get_total_orders(self):
return self.totalOrders
def submit_orders(self, service):
for _, order in self.orders.items():
service.process_order(order)
self.orders.clear()
class MrFreezie():
@backoff.on_exception(backoff.expo, NetworkException)
def connect(self):
if not bool(random.getrandbits(1)):
raise NetworkException("NETWORK TROUBLE")
pass
def process_order(self, order):
# pretend some cool order processing is happening here
return []