tasks.py 427 B

123456789101112131415
  1. from __future__ import absolute_import, print_function, unicode_literals
  2. import requests
  3. from celery import task
  4. @task(ignore_result=True)
  5. def urlopen(url):
  6. print('Opening: {0}'.format(url))
  7. try:
  8. requests.get(url)
  9. except requests.exceptions.RequestException as exc:
  10. print('Exception for {0}: {1!r}'.format(url, exc))
  11. return url, 0
  12. print('Done with: {0}'.format(url))
  13. return url, 1