This commit is contained in:
Marvin Zhang
2019-07-07 16:16:48 +08:00
parent d4bcc3c3fc
commit 9f9e603365
3 changed files with 18 additions and 3 deletions

View File

@@ -103,4 +103,4 @@ if not os.path.exists(PROJECT_LOGS_FOLDER):
if __name__ == '__main__':
# run app instance
app.run(host=FLASK_HOST, port=FLASK_PORT, threaded=True)
app.run(host=FLASK_HOST, port=FLASK_PORT)

View File

@@ -14,3 +14,4 @@ eventlet
Celery
Flower
redis
gunicorn

View File

@@ -1,3 +1,6 @@
import atexit
import fcntl
import requests
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.mongodb import MongoDBJobStore
@@ -65,8 +68,19 @@ class Scheduler(object):
print(f'running: {self.scheduler.running}')
def run(self):
self.update()
self.scheduler.start()
f = open("scheduler.lock", "wb")
try:
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
self.update()
self.scheduler.start()
except:
pass
def unlock():
fcntl.flock(f, fcntl.LOCK_UN)
f.close()
atexit.register(unlock)
scheduler = Scheduler()