Commit fadb65a7 authored by Anton Sarukhanov's avatar Anton Sarukhanov

cleanup

parent 33b134dd
......@@ -5,6 +5,7 @@ import time
from app import app, db
from models import Agency, Prediction
from nextbus import Nextbus
from lock import LockException
"""
Celery is a task queue for background task processing. We're using it
......@@ -44,11 +45,10 @@ def update_routes(agencies=None):
"""
if not agencies:
agencies = app.config['AGENCIES']
route_count = 0
for agency_tag in agencies:
route_count += len(Nextbus.get_routes(agency_tag, truncate=True))
routes = Nextbus.get_routes(agency_tag, truncate=True)
print("update_routes: Got {0} routes for {1} agencies"\
.format(route_count, len(agencies)))
.format(len(routes), len(agencies)))
@celery.task()
def update_predictions(agencies=None):
......@@ -58,10 +58,11 @@ def update_predictions(agencies=None):
start = time.time()
if not agencies:
agencies = app.config['AGENCIES']
prediction_count = len(Nextbus.get_predictions(agencies, truncate=False))
predictions = Nextbus.get_predictions(agencies,
truncate=False)
elapsed = time.time() - start
print("Got {0} predictions for {1} agencies in {2:0.2f} sec."\
.format(prediction_count, len(agencies), elapsed))
print("Got {0} predictions for {1} agencies in {2:0.2f} seconds."\
.format(len(predictions), len(agencies), elapsed))
@celery.task()
def update_vehicle_locations(agencies=None):
......@@ -71,10 +72,16 @@ def update_vehicle_locations(agencies=None):
start = time.time()
if not agencies:
agencies = app.config['AGENCIES']
vl_count = len(Nextbus.get_vehicle_locations(agencies, truncate=False))
try:
vl = Nextbus.get_vehicle_locations(agencies,
truncate=False,
max_wait=0)
except LockException as e:
print(e)
return
elapsed = time.time() - start
print("Got {0} vehicle locations for {1} agencies in {2:0.2f} seconds."\
.format(vl_count, len(agencies), elapsed))
.format(len(vl), len(agencies), elapsed))
@celery.task()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment