Skip to content

Instantly share code, notes, and snippets.

@bonnieking
Created April 24, 2013 18:58
Show Gist options
  • Save bonnieking/5454619 to your computer and use it in GitHub Desktop.
Save bonnieking/5454619 to your computer and use it in GitHub Desktop.
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