tasks.py 370 B

12345678910111213
  1. from __future__ import absolute_import, unicode_literals, print_function
  2. import requests
  3. from celery import task
  4. @task()
  5. def urlopen(url):
  6. print('-open: {0}'.format(url))
  7. try:
  8. response = requests.get(url)
  9. except requests.exceptions.RequestException as exc:
  10. print('-url {0} gave error: {1!r}'.format(url, exc))
  11. return len(response.text)