Skip to content
Snippets Groups Projects
Commit fadb65a7 authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

cleanup

parent 33b134dd
No related branches found
No related tags found
1 merge request!1Implemented Embed-code generator interface
...@@ -5,6 +5,7 @@ import time ...@@ -5,6 +5,7 @@ import time
from app import app, db from app import app, db
from models import Agency, Prediction from models import Agency, Prediction
from nextbus import Nextbus from nextbus import Nextbus
from lock import LockException
""" """
Celery is a task queue for background task processing. We're using it Celery is a task queue for background task processing. We're using it
...@@ -44,11 +45,10 @@ def update_routes(agencies=None): ...@@ -44,11 +45,10 @@ def update_routes(agencies=None):
""" """
if not agencies: if not agencies:
agencies = app.config['AGENCIES'] agencies = app.config['AGENCIES']
route_count = 0
for agency_tag in agencies: 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"\ print("update_routes: Got {0} routes for {1} agencies"\
.format(route_count, len(agencies))) .format(len(routes), len(agencies)))
@celery.task() @celery.task()
def update_predictions(agencies=None): def update_predictions(agencies=None):
...@@ -58,10 +58,11 @@ def update_predictions(agencies=None): ...@@ -58,10 +58,11 @@ def update_predictions(agencies=None):
start = time.time() start = time.time()
if not agencies: if not agencies:
agencies = app.config['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 elapsed = time.time() - start
print("Got {0} predictions for {1} agencies in {2:0.2f} sec."\ print("Got {0} predictions for {1} agencies in {2:0.2f} seconds."\
.format(prediction_count, len(agencies), elapsed)) .format(len(predictions), len(agencies), elapsed))
@celery.task() @celery.task()
def update_vehicle_locations(agencies=None): def update_vehicle_locations(agencies=None):
...@@ -71,10 +72,16 @@ def update_vehicle_locations(agencies=None): ...@@ -71,10 +72,16 @@ def update_vehicle_locations(agencies=None):
start = time.time() start = time.time()
if not agencies: if not agencies:
agencies = app.config['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 elapsed = time.time() - start
print("Got {0} vehicle locations for {1} agencies in {2:0.2f} seconds."\ 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() @celery.task()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment