Refactor code into separate method
@@ -153,9 +153,20 @@ class UsageLoggingService(Service):
def do_run(self):
start_time = time.perf_counter()
+ self.log_current_usage()
+ self.handle_expired_logs()
+
+ end_time = time.perf_counter()
+ execution_time = end_time - start_time
+
+ # Hold on until next interval
+ if execution_time < self.interval:
+ gevent.sleep(self.interval - execution_time)
+
+ def log_current_usage(self):
+ '''Updates all log files related to current reservations'''
current_reservations = Reservation.current_events()
infrastructure = self.infrastructure_manager.infrastructure
-
for reservation in current_reservations:
filename = '{id}.json'.format(id=reservation.id)
log_file_path = self.log_dir / filename
@@ -165,15 +176,6 @@ class UsageLoggingService(Service):
except Exception as e:
log.error(e)
- self.handle_expired_logs()
-
- end_time = time.perf_counter()
- execution_time = end_time - start_time
-
- # Hold on until next interval
- if execution_time < self.interval:
- gevent.sleep(self.interval - execution_time)
-
# TODO Refactor
def handle_expired_logs(self):
'''
