forked from polo2ro/imapbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
45 lines (30 loc) · 1.07 KB
/
server.py
File metadata and controls
45 lines (30 loc) · 1.07 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
42
43
44
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from utilities import errorHandler
import threading
#from imapbox import do_accounts
import croniter
import datetime
exit_flag = threading.Event()
def start_server(options, do_accounts):
"""
Starts a server, where the cron is checked every minute and the accounts are processed
help: https://crontab.guru/
"""
# test cron expression
try:
croniter.croniter(options['server'])
except Exception as e:
errorHandler(e, 'Invalid CRON expression')
print("Started server")
print("Cron: " + options['server'])
cron = croniter.croniter(options['server'], datetime.datetime.now())
next_cron = cron.get_next(datetime.datetime)
print("Waiting for first cron: " + str(next_cron))
while not exit_flag.wait(60.0):
if next_cron <= datetime.datetime.now():
# do action
do_accounts(options)
# update next cron
next_cron = cron.get_next(datetime.datetime)
print("Done. Waiting for next cron: " + str(next_cron))