-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtasks.py
More file actions
37 lines (30 loc) · 955 Bytes
/
tasks.py
File metadata and controls
37 lines (30 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import sys
import requests
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import celeryConfig
import time
from celery import Celery
from datetime import datetime
app = Celery('celeryExample')
app.config_from_object(celeryConfig)
@app.task
def heartBeat():
print('-------- inside heartbeat')
return datetime.now()
@app.task
def urlSpeed(url, method, timeout, key):
print('-------- inside urlSpeed')
try:
st = time.time()
res = requests.request(method.upper(), url, timeout=timeout)
load_time = time.time() - st
load_time = round(load_time, 1)
res.raise_for_status()
except requests.exceptions.Timeout as e:
return key, 408, "timeout exception"
except requests.HTTPError as e:
return key, -1, "Failed to get fund status from API: {}".format(str(e.errno))
except Exception as e:
return key, -2, e.args[0]
return key, 200, load_time