Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ci index schedule #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions webservice/conf/job.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ day_of_week=mon
hour=17
minute=40
second=0
misfire_grace_time=180

[regularCIMail_job]
status=1
type=cron
day_of_week=tue
hour=17
minute=40
second=0
misfire_grace_time=180
24 changes: 14 additions & 10 deletions webservice/regularCIMail.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,18 @@ def sendMail(ciIndex_thisWeek, ciIndex_lastWeek=0):
mail.send()


def main():
ciIndex_thisWeek = queryCIDataWeekly('2020-07-13 00:00:00',
'2020-07-17 00:00:00')
ciIndex_lastWeek = queryCIDataWeekly('2020-07-07 00:00:00',
'2020-07-13 00:00:00')
def regularCIMail_job():
now = datetime.datetime.now()
#获取今天零点
zeroToday = now - datetime.timedelta(
hours=now.hour,
minutes=now.minute,
seconds=now.second,
microseconds=now.microsecond)
#7天前0点
before_7Days = zeroToday - datetime.timedelta(days=7)
#14天前0点
before_14Days = zeroToday - datetime.timedelta(days=14)
ciIndex_thisWeek = queryCIDataWeekly(str(before_7Days), str(zeroToday))
ciIndex_lastWeek = queryCIDataWeekly(str(before_14Days), str(before_7Days))
sendMail(ciIndex_thisWeek, ciIndex_lastWeek)


main()

#write_excel_xls1()
10 changes: 7 additions & 3 deletions webservice/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ def daily_jobs():
executors = {'default': ThreadPoolExecutor(max_workers=30), \
'processpool': ProcessPoolExecutor(max_workers=30)}
sched = BackgroundScheduler(executors=executors)
for job in ['regularClose_job']:
for job in ['regularClose_job', 'regularCIMail_job']:
cf = localConfig.cf
sched.add_job(regularClose_job, cf.get(job, 'type'), day_of_week=cf.get(job, 'day_of_week'), hour=cf.get(job, 'hour'), minute=cf.get(job, 'minute'), \
second=cf.get(job, 'second'), misfire_grace_time=int(cf.get(job, 'misfire_grace_time')))
if job == 'regularClose_job':
sched.add_job(regularClose_job, cf.get(job, 'type'), day_of_week=cf.get(job, 'day_of_week'), hour=cf.get(job, 'hour'), minute=cf.get(job, 'minute'), \
second=cf.get(job, 'second'), misfire_grace_time=int(cf.get(job, 'misfire_grace_time')))
elif job == 'regularCIMail_job':
sched.add_job(regularCIMail_job, cf.get(job, 'type'), day_of_week=cf.get(job, 'day_of_week'), hour=cf.get(job, 'hour'), minute=cf.get(job, 'minute'), \
second=cf.get(job, 'second'), misfire_grace_time=int(cf.get(job, 'misfire_grace_time')))
sched.add_listener(job_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
sched._logger = logging
sched.start()
Expand Down