From c502b8c348c03acb9d1fbc8a1280ea2fd7732f6a Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 24 Apr 2017 13:38:11 +0200 Subject: [PATCH] [fix] Add random delay to app fetchlist cron job (#297) * Add random delay to app fetchlist cron job * Split the sleep and yunohost command on two lines --- src/yunohost/app.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 10f61722..2f80d0ac 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1933,8 +1933,15 @@ def _install_appslist_fetch_cron(): logger.debug("Installing appslist fetch cron job") + cron_job = [] + cron_job.append("#!/bin/bash") + # We add a random delay between 0 and 60 min to avoid every instance fetching + # the appslist at the same time every night + cron_job.append("(sleep $((RANDOM%3600));") + cron_job.append("yunohost app fetchlist > /dev/null 2>&1) &") + with open(cron_job_file, "w") as f: - f.write('#!/bin/bash\n\nyunohost app fetchlist > /dev/null 2>&1\n') + f.write('\n'.join(cron_job)) _set_permissions(cron_job_file, "root", "root", 0755)