Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop processing in create_usage_records job if it took more than 15min #2260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions press/press/doctype/subscription/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from __future__ import annotations

from datetime import datetime, timedelta

import frappe
import rq
from frappe.model.document import Document
Expand Down Expand Up @@ -252,6 +254,7 @@
"""
Creates daily usage records for paid Subscriptions
"""
start_time = datetime.now()

Check warning on line 257 in press/press/doctype/subscription/subscription.py

View check run for this annotation

Codecov / codecov/patch

press/press/doctype/subscription/subscription.py#L257

Added line #L257 was not covered by tests
free_sites = sites_with_free_hosting()
settings = frappe.get_single("Press Settings")
subscriptions = frappe.db.get_all(
Expand All @@ -271,6 +274,10 @@
for name in subscriptions:
if has_job_timeout_exceeded():
return
if timedelta(datetime.now() - start_time).total_seconds() > 900:

Check warning on line 277 in press/press/doctype/subscription/subscription.py

View check run for this annotation

Codecov / codecov/patch

press/press/doctype/subscription/subscription.py#L277

Added line #L277 was not covered by tests
# if job takes more than 15 minutes, stop process pending ones
# those ones will be picked up in the next job
break

Check warning on line 280 in press/press/doctype/subscription/subscription.py

View check run for this annotation

Codecov / codecov/patch

press/press/doctype/subscription/subscription.py#L280

Added line #L280 was not covered by tests
subscription = frappe.get_cached_doc("Subscription", name)
try:
subscription.create_usage_record()
Expand Down
Loading