mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* Support 202307 Add hover tip to describe meaning of routeserver icon #1381 Add Campus and Carrier Tooltips #1361 Display website URL on all non-org objects #1300 Make the search field on cp/peeringdb_server/network/ aware of leading AS/ASN #1027 Add search field to `/cp/peeringdb_server/` AC views (#1239) IX-F Importer: IX-F Member Data not being nullified after IX stops/changes import #1360 Include carrier and campus objects in the API #1352 * fixes to website propagation * fix tests * django-security-keys to 1.1.0 and relock * poetry relock * linting * comment django-peeringdb dev mount * add org website field to admin forms * fix templatetag name collision between django-security-keys and peeringdb * linting * django-peeringdb to 3.2.0 and poetry relock * remove debug message --------- Co-authored-by: 20C <code@20c.com>
60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
"""
|
|
Runs the pdb_load_data command on a randomized interval
|
|
|
|
Minimum interval is set through PEERINGDB_SYNC_INTERVAL environment variable (seconds)
|
|
and will default to 15 minutes if not set.
|
|
|
|
A random offset of up to 15 minutes will be appalied.
|
|
"""
|
|
|
|
import os
|
|
import random
|
|
import subprocess
|
|
import time
|
|
|
|
import structlog
|
|
|
|
# Configure logging
|
|
logger = structlog.getLogger(__name__)
|
|
|
|
|
|
def run_pdb_load_data():
|
|
command = "python manage.py pdb_load_data --commit"
|
|
directory = "/srv/www.peeringdb.com/"
|
|
|
|
subprocess.call(command, shell=True, cwd=directory)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
PEERINGDB_SYNC_INTERVAL = int(
|
|
os.environ.get("PEERINGDB_SYNC_INTERVAL", 15 * 60)
|
|
)
|
|
except ValueError:
|
|
PEERINGDB_SYNC_INTERVAL = 1
|
|
|
|
default_sleep = PEERINGDB_SYNC_INTERVAL
|
|
|
|
# apply a maximum offset of 15 minutes
|
|
max_sleep = default_sleep + (15 * 60)
|
|
|
|
logger.info("Starting pdb_load_data daemon...")
|
|
|
|
first_run = True
|
|
|
|
while bool(PEERINGDB_SYNC_INTERVAL):
|
|
# sleep for a random amount of time between the default interval
|
|
# and the maximum interval
|
|
if first_run:
|
|
sleep_time = 0
|
|
else:
|
|
sleep_time = random.randint(default_sleep, max_sleep)
|
|
logger.info(f"Sleeping for {sleep_time} seconds...")
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
run_pdb_load_data()
|
|
logger.info("Data loaded successfully.")
|
|
|
|
first_run = False
|