I am using Apscheduler’s BackgroundScheduler
that executes an API call and does a few other things. The job runs but it gets executed three times as I am using three workers (makes sense). Based on what I have read, I added --preload
but now the scheduled job runs four times.
gunicorn
gunicorn --bind=0.0.0.0 --timeout=120 --workers=3 --worker-connections=1000 --worker-class=gevent --preload app:server
app.py
app = DashProxy(__name__, external_stylesheets=external_stylesheets,
title='Dashboard', use_pages=True,
transforms=[ServersideOutputTransform()])
server = app.server
auth = GoogleAuth(app) # Google OAuth
# dash layout , callbacks, etc. here
def scheduled_job():
try:
dd.update_data()
# remove backend files
for file in glob.glob(pathname='file_system_backend/*', include_hidden=True):
os.remove(file)
SMTP.send_email(subject='Dashboard Updated',
body='The dashboard has been successfully updated.',
recipients='xxxxxx')
# Send an email on error
except Exception as err:
SMTP.send_email(subject=f'Dashboard {type(err)}',
body=str(err),
recipients='xxxxxx')
scheduler = BackgroundScheduler(timezone='UTC')
scheduler.add_job(func=scheduled_job, trigger='cron', hour=8, minute=0)
scheduler.start()
if __name__ == '__main__':
app.run(debug=False)
Any advice on how to have the scheduled job execute only once? I do not need to use Apscheduler
if there are other suggestions.