Skip to content

Commit

Permalink
Scheduler assigned the cron job
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniz Türkmen authored and Deniz Türkmen committed Oct 23, 2024
1 parent a823cd4 commit cdf34b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions web/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ def register_extensions(app):
migrate.init_app(app, db)
bootstrap.init_app(app)

'''
if scheduler.state == 0:
print("Scheduler init app")
scheduler.init_app(app)
logging.getLogger("apscheduler").setLevel(logging.INFO)
print("Scheduler start")
scheduler.start()
'''
return app


Expand Down
9 changes: 9 additions & 0 deletions web/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ class PostgresConfig(Config):
user=POSTGRES_USER, pw=POSTGRES_PW, url=POSTGRES_URL, db=POSTGRES_DB
)

JOBS = [
{
"id": "update_server",
"func": 'app.services.cron_service:check_db_sessions',
"trigger": "interval",
"seconds": int(os.environ.get("INTERVAL_DB_CHECK")) or 3,
}
]


class TestConfig(Config):
TESTING = True
Expand Down
14 changes: 14 additions & 0 deletions web/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


def on_starting(server):
print("Gunicorn master process is starting...")

def when_ready(server):
from app.app import create_app, scheduler
app = create_app() # Create an instance of the app
with app.app_context():
print("Initializing and starting scheduler inside Gunicorn master process")
scheduler.init_app(app) # Initialize the scheduler
scheduler.start() # Start the scheduler

print("Scheduler started in Gunicorn master process")

0 comments on commit cdf34b2

Please sign in to comment.