Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions landoapi/models/landing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class LandingJobStatus(enum.Enum):
# Manually cancelled state.
CANCELLED = "CANCELLED"

@classmethod
@property
def ACTIVE_STATUSES(cls):
return (
cls.SUBMITTED,
cls.DEFERRED,
cls.IN_PROGRESS,
)


@enum.unique
class LandingJobAction(enum.Enum):
Expand Down Expand Up @@ -233,12 +242,7 @@ def job_queue_query(
grace_seconds (int): Ignore landing jobs that were submitted after this
many seconds ago.
"""
applicable_statuses = (
LandingJobStatus.SUBMITTED,
LandingJobStatus.IN_PROGRESS,
LandingJobStatus.DEFERRED,
)
q = cls.query.filter(cls.status.in_(applicable_statuses))
q = cls.query.filter(cls.status.in_(LandingJobStatus.ACTIVE_STATUSES))

if repositories:
q = q.filter(cls.repository_name.in_(repositories))
Expand Down
1 change: 0 additions & 1 deletion landoapi/workers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def refresh_enabled_repos(self):
for r in self.applicable_repos
if treestatus_subsystem.client.is_open(repo_clone_subsystem.repos[r].tree)
]
logger.info(f"{len(self.enabled_repos)} enabled repos: {self.enabled_repos}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was removing this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am not sure if it is a useful thing to have in the logs constantly, since this is basically the repos in the environment variable, minus any trees that are closed. Perhaps it makes more sense to add it as a warning instead, if the two don't match?


def start(self, max_loops: int | None = None):
"""Run setup sequence and start the event loop."""
Expand Down
36 changes: 32 additions & 4 deletions landoapi/workers/landing_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
TreeClosed,
)
from landoapi.models.configuration import ConfigurationKey
from landoapi.models.landing_job import LandingJob, LandingJobAction, LandingJobStatus
from landoapi.models.landing_job import (
LandingJob,
LandingJobAction,
LandingJobStatus,
)
from landoapi.notifications import (
notify_user_of_bug_update_failure,
notify_user_of_landing_failure,
Expand Down Expand Up @@ -71,6 +75,9 @@ def job_processing(worker: LandingWorker, job: LandingJob, db: SQLAlchemy):


class LandingWorker(Worker):
TOO_MANY_ATTEMPTS_THRESHOLD = 10
QUEUE_SIZE_THRESHOLD = 20

@property
def STOP_KEY(self) -> ConfigurationKey:
"""Return the configuration key that prevents the worker from starting."""
Expand All @@ -86,11 +93,32 @@ def __init__(self, *args, **kwargs):
self.last_job_finished = None
self.refresh_enabled_repos()

def loop(self):
logger.debug(
f"{len(self.applicable_repos)} applicable repos: {self.applicable_repos}"
def check_landing_worker_warnings(self):
"""Log messages that show various important statistics about the landing worker."""

queue_size = LandingJob.query.filter(
LandingJob.status.in_(LandingJobStatus.ACTIVE_STATUSES)
).count()
if queue_size >= self.QUEUE_SIZE_THRESHOLD:
logger.warning(
f"The landing queue size of {queue_size} exceeds threshold of "
f"{self.QUEUE_SIZE_THRESHOLD}."
)

runaway_jobs = LandingJob.query.filter(
LandingJob.status.in_(LandingJobStatus.ACTIVE_STATUSES),
LandingJob.attempts >= self.TOO_MANY_ATTEMPTS_THRESHOLD,
)

if runaway_jobs.count() > 0:
job = runaway_jobs.all()[0]
logger.warning(
f"Active landing job ({job}) has too many attempts ({job.attempts})"
)
Comment on lines +113 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we cancel the job in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a good idea, but I think it would be outside the scope of this PR since it would require us to also send a notification email. Maybe it can be done as a follow up.


def loop(self):
self.check_landing_worker_warnings()

# Check if any closed trees reopened since the beginning of this iteration
if len(self.enabled_repos) != len(self.applicable_repos):
self.refresh_enabled_repos()
Expand Down