Skip to content

Commit

Permalink
Changes not use job queue if Package data exists in the cache.
Browse files Browse the repository at this point in the history
Signed-off-by: Kouhei Maeda <mkouhei@palmtb.net>
  • Loading branch information
mkouhei committed Jun 17, 2015
1 parent 6388e2d commit a765128
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
10 changes: 9 additions & 1 deletion pgraph/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import sys
from celery import Celery
from py_deps import Package
from py_deps import Package, Container
if sys.version_info < (3, 0):
# pylint: disable=import-error
import ConfigParser as configparser
Expand Down Expand Up @@ -39,6 +39,14 @@ def gen_dependency(pkg_name, version):
return Package(pkg_name, version=version)


def read_cache(pkg_name, version):
"""Check cache and read data."""
if Container().read_data((pkg_name, version)):
return Package(pkg_name, version=version)
else:
return


def search(pkg_name):
"""Search package."""
return Package.search(pkg_name)
Expand Down
25 changes: 16 additions & 9 deletions pgraph/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,22 @@ def linkdraw(self):
pkg_name = self.request.matchdict['pkg']
version = self.request.matchdict['version']
self.meta['pkg_name'] = pkg_name
job = tasks.gen_dependency.delay(pkg_name, version)
while job.ready() is False:
time.sleep(1)
if job.successful():
result = job.result.draw('linkdraw',
decode_type='json',
disable_time=True,
disable_descr=True)
return result
data = tasks.read_cache(pkg_name, version)
if data:
result = data.draw('linkdraw',
decode_type='json',
disable_time=True,
disable_descr=True)
else:
job = tasks.gen_dependency.delay(pkg_name, version)
while job.ready() is False:
time.sleep(1)
if job.successful():
result = job.result.draw('linkdraw',
decode_type='json',
disable_time=True,
disable_descr=True)
return result

@view_config(route_name='graph', renderer='templates/graph.pt')
def graph(self):
Expand Down

0 comments on commit a765128

Please sign in to comment.