mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-22 16:48:36 +02:00
feat: prevent background tasks from running all at once
This commit is contained in:
@@ -17,7 +17,12 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="0 4 * * *")
|
@app.periodic(cron="0 4 * * *")
|
||||||
@app.task(queueing_lock="remove_old_jobs", pass_context=True, name="remove_old_jobs")
|
@app.task(
|
||||||
|
lock="remove_old_jobs",
|
||||||
|
queueing_lock="remove_old_jobs",
|
||||||
|
pass_context=True,
|
||||||
|
name="remove_old_jobs",
|
||||||
|
)
|
||||||
async def remove_old_jobs(context, timestamp):
|
async def remove_old_jobs(context, timestamp):
|
||||||
try:
|
try:
|
||||||
return await builtin_tasks.remove_old_jobs(
|
return await builtin_tasks.remove_old_jobs(
|
||||||
@@ -36,7 +41,11 @@ async def remove_old_jobs(context, timestamp):
|
|||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="0 6 1 * *")
|
@app.periodic(cron="0 6 1 * *")
|
||||||
@app.task(queueing_lock="remove_expired_sessions", name="remove_expired_sessions")
|
@app.task(
|
||||||
|
lock="remove_expired_sessions",
|
||||||
|
queueing_lock="remove_expired_sessions",
|
||||||
|
name="remove_expired_sessions",
|
||||||
|
)
|
||||||
async def remove_expired_sessions(timestamp=None):
|
async def remove_expired_sessions(timestamp=None):
|
||||||
"""Cleanup expired sessions by using Django management command."""
|
"""Cleanup expired sessions by using Django management command."""
|
||||||
try:
|
try:
|
||||||
@@ -49,7 +58,7 @@ async def remove_expired_sessions(timestamp=None):
|
|||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="0 8 * * *")
|
@app.periodic(cron="0 8 * * *")
|
||||||
@app.task(name="reset_demo_data")
|
@app.task(lock="reset_demo_data", name="reset_demo_data")
|
||||||
def reset_demo_data(timestamp=None):
|
def reset_demo_data(timestamp=None):
|
||||||
"""
|
"""
|
||||||
Wipes the database and loads fresh demo data if DEMO mode is active.
|
Wipes the database and loads fresh demo data if DEMO mode is active.
|
||||||
@@ -86,9 +95,7 @@ def reset_demo_data(timestamp=None):
|
|||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="0 */12 * * *") # Every 12 hours
|
@app.periodic(cron="0 */12 * * *") # Every 12 hours
|
||||||
@app.task(
|
@app.task(lock="check_for_updates", name="check_for_updates")
|
||||||
name="check_for_updates",
|
|
||||||
)
|
|
||||||
def check_for_updates(timestamp=None):
|
def check_for_updates(timestamp=None):
|
||||||
if not settings.CHECK_FOR_UPDATES:
|
if not settings.CHECK_FOR_UPDATES:
|
||||||
return "CHECK_FOR_UPDATES is disabled"
|
return "CHECK_FOR_UPDATES is disabled"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="0 * * * *") # Run every hour
|
@app.periodic(cron="0 * * * *") # Run every hour
|
||||||
@app.task(name="automatic_fetch_exchange_rates")
|
@app.task(lock="automatic_fetch_exchange_rates", name="automatic_fetch_exchange_rates")
|
||||||
def automatic_fetch_exchange_rates(timestamp=None):
|
def automatic_fetch_exchange_rates(timestamp=None):
|
||||||
"""Fetch exchange rates for all due services"""
|
"""Fetch exchange rates for all due services"""
|
||||||
fetcher = ExchangeRateFetcher()
|
fetcher = ExchangeRateFetcher()
|
||||||
@@ -19,7 +19,7 @@ def automatic_fetch_exchange_rates(timestamp=None):
|
|||||||
logger.error(e, exc_info=True)
|
logger.error(e, exc_info=True)
|
||||||
|
|
||||||
|
|
||||||
@app.task(name="manual_fetch_exchange_rates")
|
@app.task(lock="manual_fetch_exchange_rates", name="manual_fetch_exchange_rates")
|
||||||
def manual_fetch_exchange_rates(timestamp=None):
|
def manual_fetch_exchange_rates(timestamp=None):
|
||||||
"""Fetch exchange rates for all due services"""
|
"""Fetch exchange rates for all due services"""
|
||||||
fetcher = ExchangeRateFetcher()
|
fetcher = ExchangeRateFetcher()
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="0 0 * * *")
|
@app.periodic(cron="0 0 * * *")
|
||||||
@app.task(name="generate_recurring_transactions")
|
@app.task(
|
||||||
|
lock="generate_recurring_transactions", name="generate_recurring_transactions"
|
||||||
|
)
|
||||||
def generate_recurring_transactions(timestamp=None):
|
def generate_recurring_transactions(timestamp=None):
|
||||||
try:
|
try:
|
||||||
RecurringTransaction.generate_upcoming_transactions()
|
RecurringTransaction.generate_upcoming_transactions()
|
||||||
@@ -26,7 +28,7 @@ def generate_recurring_transactions(timestamp=None):
|
|||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="10 1 * * *")
|
@app.periodic(cron="10 1 * * *")
|
||||||
@app.task(name="cleanup_deleted_transactions")
|
@app.task(lock="cleanup_deleted_transactions", name="cleanup_deleted_transactions")
|
||||||
def cleanup_deleted_transactions(timestamp=None):
|
def cleanup_deleted_transactions(timestamp=None):
|
||||||
if settings.ENABLE_SOFT_DELETE and settings.KEEP_DELETED_TRANSACTIONS_FOR == 0:
|
if settings.ENABLE_SOFT_DELETE and settings.KEEP_DELETED_TRANSACTIONS_FOR == 0:
|
||||||
return "KEEP_DELETED_TRANSACTIONS_FOR is 0, no cleanup performed."
|
return "KEEP_DELETED_TRANSACTIONS_FOR is 0, no cleanup performed."
|
||||||
|
|||||||
Reference in New Issue
Block a user