-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathceleryTask.py
More file actions
41 lines (39 loc) · 1.16 KB
/
Copy pathceleryTask.py
File metadata and controls
41 lines (39 loc) · 1.16 KB
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
38
39
40
41
from celery import Celery
from modules import crawler
from datetime import datetime,timedelta
from modules.db import pgTestClass as ptc
app = Celery('async_runner')
app.config_from_object('celeryConfig')
@app.task(ignore_result=True)
def runSth():
print('run something in flask !')
@app.task(ignore_result=True)
def add(a,b):
return a+b
# 定期爬youbike各站資料
@app.task
def runCrawler():
print('begin to run crawler')
dataSet = crawler.showAll()
print('get ubike data')
crawler.putData(dataSet)
print('insert complete')
# 計算使用率並顯示於flask
@app.task(ignore_result=True,default_retry_delay=30, max_retries=3, soft_time_limit=10000)
def runAnalyse(sno):
countDown = 4
date_list = []
avg_list = []
run = ptc.DataConnection()
print('begin to run analyzer')
while countDown>1:
d = datetime.now().date()-timedelta(days=countDown)
date = d.strftime('%Y-%m-%d')
dtime,avg = run.avg_use_rate(sno,date)
date_list = date_list+dtime
avg_list = avg_list+avg
countDown = countDown-1
print('done')
run.cursor.close()
run.conn.close()
return date_list,avg_list