euscanwww: Upgraded to Celery 3.0 and fixed scan_portage

Fixed TaskSet calls and synchronous stuff. Everything should be
deadlock safe

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-07-07 18:09:14 +02:00
parent 3be52a710c
commit 03cf3b90a4
4 changed files with 32 additions and 29 deletions

View File

@ -4,8 +4,7 @@ Celery tasks for djeuscan
from itertools import islice from itertools import islice
from celery.task import task from celery.task import task, group, chord
from celery.task.sets import TaskSet
from django.conf import settings from django.conf import settings
@ -34,7 +33,7 @@ def _run_in_chunks(task, packages, kwargs=None,
concurrently=settings.TASKS_CONCURRENTLY, concurrently=settings.TASKS_CONCURRENTLY,
n=settings.TASKS_SUBTASK_PACKAGES): n=settings.TASKS_SUBTASK_PACKAGES):
""" """
Launches a TaskSet at a time with <concurrently> subtasks. Launches a group at a time with <concurrently> subtasks.
Each subtask has <n> packages to handle Each subtask has <n> packages to handle
""" """
output = [] output = []
@ -51,10 +50,7 @@ def _run_in_chunks(task, packages, kwargs=None,
done = True done = True
else: else:
tasks.append(task.subtask((chunk, ), kwargs)) tasks.append(task.subtask((chunk, ), kwargs))
job = TaskSet(tasks=tasks) output.extend(group(tasks)())
result = job.apply_async()
# TODO: understand why this causes timeout
output.extend(list(result.join()))
return output return output
@ -107,8 +103,9 @@ def scan_metadata_all_task():
@task @task
def _scan_portage_task(packages, no_log=False, purge_packages=False, def _scan_portage_task(packages, category=None, no_log=False,
purge_versions=False, prefetch=False): purge_packages=False, purge_versions=False,
prefetch=False):
""" """
Scans portage for the given set of packages Scans portage for the given set of packages
""" """
@ -121,6 +118,7 @@ def _scan_portage_task(packages, no_log=False, purge_packages=False,
scan_portage( scan_portage(
packages=packages, packages=packages,
category=category,
no_log=no_log, no_log=no_log,
purge_packages=purge_packages, purge_packages=purge_packages,
purge_versions=purge_versions, purge_versions=purge_versions,
@ -138,8 +136,9 @@ def scan_portage_list_task(query, no_log=False, purge_packages=False,
""" """
kwargs = {"no_log": no_log, "purge_packages": purge_packages, kwargs = {"no_log": no_log, "purge_packages": purge_packages,
"purge_versions": purge_versions, "prefetch": prefetch} "purge_versions": purge_versions, "prefetch": prefetch}
return _run_in_chunks(_scan_portage_task, [p for p in query.split()], return _run_in_chunks(
kwargs) _scan_portage_task, [p for p in query.split()], kwargs
)
@task @task
@ -148,8 +147,9 @@ def scan_portage_all_task(no_log=False, purge_packages=False,
""" """
Runs a syncronous portage scan for all packages Runs a syncronous portage scan for all packages
""" """
return _scan_portage_task( _scan_portage_task(
packages=None, packages=None,
category=None,
no_log=no_log, no_log=no_log,
purge_packages=purge_packages, purge_packages=purge_packages,
purge_versions=purge_versions, purge_versions=purge_versions,
@ -214,7 +214,7 @@ def update_portage_trees_task():
@task @task
def update_task(update_portage_trees=True, scan_portage=True, def update_task(update_portage_trees=True, scan_portage=True,
scan_metadata=True, scan_upstream=True, update_counter=True): scan_metadata=True, scan_upstream=True, update_counters=True):
""" """
Update the whole euscan system Update the whole euscan system
""" """
@ -225,21 +225,21 @@ def update_task(update_portage_trees=True, scan_portage=True,
purge_versions=True) purge_versions=True)
# metadata and upstream scan can run concurrently, launch them # metadata and upstream scan can run concurrently, launch them
# asynchronously and wait for them to finish # in a group and wait for them to finish
metadata_job = None tasks = []
if scan_metadata: if scan_metadata:
metadata_job = scan_metadata_all_task().delay() tasks.append(scan_metadata_all_task.subtask())
upstream_job = None
if scan_upstream: if scan_upstream:
upstream_job = scan_upstream_all_task().delay() tasks.append(scan_upstream_all_task.subtask())
if metadata_job: if update_counters:
metadata_job.wait() chord(tasks)(
if upstream_job: # immutable means that the result of previous tasks is not passed
upstream_job.wait() update_counters_task.subtask((), {"fast": False}, immutable=True)
)
update_counters(fast=False) else:
group(tasks)()
@task @task

View File

@ -225,7 +225,9 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# djeuscan tasks # djeuscan tasks
PORTAGE_ROOT = "/" PORTAGE_ROOT = "/"
PORTAGE_CONFIGROOT = "/" PORTAGE_CONFIGROOT = "/"
EIX_CACHEFILE = os.path.join(PORTAGE_ROOT, 'var/cache/eix')
LAYMAN_CONFIG = "/etc/layman/layman.cfg" LAYMAN_CONFIG = "/etc/layman/layman.cfg"
EGENCACHE_JOBS = 4 EGENCACHE_JOBS = 4
# Celery config # Celery config
@ -236,7 +238,7 @@ CELERY_RESULT_BACKEND = "amqp"
BROKER_CONNECTION_TIMEOUT = 3600 BROKER_CONNECTION_TIMEOUT = 3600
CELERYD_CONCURRENCY = 4 CELERYD_CONCURRENCY = 4
TASKS_CONCURRENTLY = 4 TASKS_CONCURRENTLY = 8
TASKS_SUBTASK_PACKAGES = 32 TASKS_SUBTASK_PACKAGES = 32
CELERYBEAT_SCHEDULE = { CELERYBEAT_SCHEDULE = {
@ -275,4 +277,4 @@ except ImportError, ex:
os.environ['ROOT'] = PORTAGE_ROOT os.environ['ROOT'] = PORTAGE_ROOT
os.environ['PORTAGE_CONFIGROOT'] = PORTAGE_CONFIGROOT os.environ['PORTAGE_CONFIGROOT'] = PORTAGE_CONFIGROOT
os.environ['EIX_CACHEFILE'] = os.path.join(PORTAGE_ROOT, 'var/cache/eix') os.environ['EIX_CACHEFILE'] = EIX_CACHEFILE

View File

@ -17,6 +17,7 @@ import euscan
from euscan import CONFIG, BLACKLIST_VERSIONS, ROBOTS_TXT_BLACKLIST_DOMAINS from euscan import CONFIG, BLACKLIST_VERSIONS, ROBOTS_TXT_BLACKLIST_DOMAINS
from euscan.version import parse_version from euscan.version import parse_version
def htop_vercmp(a, b): def htop_vercmp(a, b):
def fixver(v): def fixver(v):
if v in ['0.11', '0.12', '0.13']: if v in ['0.11', '0.12', '0.13']:
@ -179,8 +180,8 @@ def simple_vercmp(a, b):
return r return r
# Fallback # Fallback
a = pkg_parse_version(a) a = parse_version(a)
b = pkg_parse_version(b) b = parse_version(b)
if a < b: if a < b:
return -1 return -1

View File

@ -90,7 +90,7 @@ setup(
install_requires=[ install_requires=[
'Django==1.4', 'django-annoying==0.7.6', 'South==0.7.4', 'Django==1.4', 'django-annoying==0.7.6', 'South==0.7.4',
'django-piston==0.2.3', 'BeautifulSoup==3.2.1', 'matplotlib==1.1.0', 'django-piston==0.2.3', 'BeautifulSoup==3.2.1', 'matplotlib==1.1.0',
'django-celery==2.5.5', 'django-registration==0.8', 'django-celery==3.0.0', 'django-registration==0.8',
'python-ldap==2.4.10', 'django-auth-ldap==1.1', 'python-ldap==2.4.10', 'django-auth-ldap==1.1',
], ],
package_dir={'': 'pym'}, package_dir={'': 'pym'},