Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PyBusMap
Manage
Activity
Members
Labels
Plan
Issues
10
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Sarukhanov
PyBusMap
Commits
fadb65a7
Commit
fadb65a7
authored
8 years ago
by
Anton Sarukhanov
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
33b134dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Implemented Embed-code generator interface
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
celerytasks.py
+15
-8
15 additions, 8 deletions
celerytasks.py
with
15 additions
and
8 deletions
celerytasks.py
+
15
−
8
View file @
fadb65a7
...
@@ -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
)
)
route
s
=
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
(
route
s
)
,
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} sec
onds
.
"
\
.
format
(
prediction
_count
,
len
(
agencies
),
elapsed
))
.
format
(
len
(
prediction
s
)
,
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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment