mirror of
https://github.com/YunoHost-Apps/aeneria_ynh.git
synced 2024-09-03 18:06:15 +02:00
Implement random cron schedule
This commit is contained in:
parent
82bacd2127
commit
2b5bd3cd88
4 changed files with 23 additions and 1 deletions
|
@ -1 +1 @@
|
|||
*/20 * * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/bin/console aeneria:fetch-data
|
||||
__MINUTES__ __HOUR__-23/3 * * * __APP__ /usr/bin/php__PHPVERSION__ __FINALPATH__/bin/console aeneria:fetch-data
|
||||
|
|
|
@ -12,6 +12,17 @@ pkg_dependencies="apt-transport-https postgresql postgresql-contrib php${YNH_PHP
|
|||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
# Assign two variables:
|
||||
# minutes: random value between 00 and 59 (MM)
|
||||
# hour: random value between 0 and 2
|
||||
# It is used for the cronjob, so that it runs every 3 hours starting at 00:MM, 01:MM, or 02:MM.
|
||||
generate_random_minutes_hour () {
|
||||
minutes="$(ynh_string_random --length=1 --filter=0-5)$(ynh_string_random --length=1 --filter=0-9)"
|
||||
hour="$(ynh_string_random --length=1 --filter=0-2)"
|
||||
ynh_app_setting_set --app=$app --key=minutes --value=$minutes
|
||||
ynh_app_setting_set --app=$app --key=hour --value=$hour
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -149,6 +149,9 @@ popd
|
|||
#=================================================
|
||||
ynh_script_progression --message="Setuping a cron..." --weight=1
|
||||
|
||||
# Generate random running schedule, and save $hour and $minutes as app parameters
|
||||
generate_random_minutes_hour
|
||||
|
||||
ynh_add_config --template="../conf/aeneria.cron" --destination="/etc/cron.d/$app"
|
||||
chown root: "/etc/cron.d/$app"
|
||||
chmod 644 "/etc/cron.d/$app"
|
||||
|
|
|
@ -25,6 +25,8 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
|||
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||
deskey=$(ynh_app_setting_get --app=$app --key=deskey)
|
||||
db_user="$db_name"
|
||||
hour=$(ynh_app_setting_get --app=$app --key=hour)
|
||||
minutes=$(ynh_app_setting_get --app=$app --key=minutes)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
|
@ -66,6 +68,12 @@ if [ -z "$final_path" ]; then
|
|||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
fi
|
||||
|
||||
# If minutes or hour do not exist, create them
|
||||
if [ -z "$minutes" ] || [ -z "$hour" ]; then
|
||||
# Generate random running schedule, and save $hour and $minutes as app parameters
|
||||
generate_random_minutes_hour
|
||||
fi
|
||||
|
||||
# Cleaning legacy permissions
|
||||
if ynh_legacy_permissions_exists; then
|
||||
ynh_legacy_permissions_delete_all
|
||||
|
|
Loading…
Add table
Reference in a new issue