Created
April 24, 2013 18:58
-
-
Save bonnieking/5454619 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.cache import cache | |
from django.utils.hashcompat import md5_constructor as md5 | |
from RHEL_scrape.rhlistupdates import RHListUpdates | |
import updateinfo | |
from consumers.xml_web.import_entry import ImportEntry | |
LOCK_EXPIRE = 60 * 5 # Lock expires in 5 minutes | |
@task | |
def scraperhn(file=default_conf, debug=True, section=section, updateinfo=FILE): | |
section_digest = md5(section).hexdigest() | |
lock_id = "celery-lock-%s" % (section_digest) | |
acquire_lock = lambda: cache.add(lock_id, "true", 300) | |
release_lock = lambda: cache.delete(lock_id) | |
if acquire_lock(): | |
try: | |
list_updates = RHListUpdates(configfile=default_conf, updateinfo=updateinfo, section=section, debug=True) | |
xml = list_updates.parse_urls() | |
f = open(savefile, 'w+') | |
f.write(xml) | |
f.close() | |
finally: | |
release_lock() | |
return section | |
else: | |
return "didn't get lock" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment