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

Add TTL for agents and advertised queues #294

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add TTL for agents and advertised queues
  • Loading branch information
plars committed Jun 26, 2024
commit ec074b15b62c54df2fe7f03f5fb3027e8099554e
2 changes: 2 additions & 0 deletions agent/testflinger_agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def start_agent():
)
while agent.check_offline():
time.sleep(check_interval)
# Refresh the updated_at timestamp on advertised queues
client.post_advertised_queues()
logger.info("Checking jobs")
agent.process_jobs()
logger.info("Sleeping for {}".format(check_interval))
Expand Down
5 changes: 3 additions & 2 deletions server/src/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

import uuid
from datetime import datetime
from datetime import datetime, timezone

import pkg_resources
from apiflask import APIBlueprint, abort
Expand Down Expand Up @@ -405,10 +405,11 @@ def queues_post():
the user can check which queues are valid to use.
"""
queue_dict = request.get_json()
timestamp = datetime.now(timezone.utc)
for queue, description in queue_dict.items():
database.mongo.db.queues.update_one(
{"name": queue},
{"$set": {"description": description}},
{"$set": {"description": description, "updated_at": timestamp}},
upsert=True,
)
return "OK"
Expand Down
10 changes: 10 additions & 0 deletions server/src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ def create_indexes():
"uploadDate", expireAfterSeconds=DEFAULT_EXPIRATION
)

# Remove agents that haven't checked in for 7 days
mongo.db.agents.create_index(
"updated_at", expireAfterSeconds=DEFAULT_EXPIRATION
)

# Remove advertised queues that haven't updated in over 7 days
mongo.db.queues.create_index(
"updated_at", expireAfterSeconds=DEFAULT_EXPIRATION
)

# Faster lookups for common queries
mongo.db.jobs.create_index("job_id")
mongo.db.jobs.create_index(["result_data.job_state", "job_data.job_queue"])
Expand Down