1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/aeneria_ynh.git synced 2024-09-03 18:06:15 +02:00

Merge pull request #32 from YunoHost-Apps/enh-cron

Implement random cron schedule
This commit is contained in:
tituspijean 2023-02-23 19:46:48 +01:00 committed by GitHub
commit a6e601d10b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 24 deletions

View file

@ -5,7 +5,7 @@ It shall NOT be edited by hand.
# æneria for YunoHost # æneria for YunoHost
[![Integration level](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg) [![Integration level](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![Working status](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg)
[![Install æneria with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=aeneria) [![Install æneria with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=aeneria)
*[Lire ce readme en français.](./README_fr.md)* *[Lire ce readme en français.](./README_fr.md)*
@ -23,11 +23,9 @@ The idea of [æneria](https://aeneria.com) is to display energy consumption and
**Shipped version:** 1.1.6~ynh2 **Shipped version:** 1.1.6~ynh2
## Screenshots ## Screenshots
![](./doc/screenshots/screenshot1.png) ![Screenshot of æneria](./doc/screenshots/screenshot1.png)
## Disclaimers / important information ## Disclaimers / important information
@ -48,21 +46,22 @@ But don't worry, you can easilly transfer your data from Pilea to æneria follow
## Documentation and resources ## Documentation and resources
* Official app website: https://aeneria.com * Official app website: <https://aeneria.com>
* Official admin documentation: https://docs.aeneria.com * Official admin documentation: <https://docs.aeneria.com>
* Upstream app code repository: https://gitlab.com/aeneria/aeneria-app * Upstream app code repository: <https://gitlab.com/aeneria/aeneria-app>
* YunoHost documentation for this app: https://yunohost.org/app_aeneria * YunoHost documentation for this app: <https://yunohost.org/app_aeneria>
* Report a bug: https://github.com/YunoHost-Apps/aeneria_ynh/issues * Report a bug: <https://github.com/YunoHost-Apps/aeneria_ynh/issues>
## Developer info ## Developer info
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing). Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing).
To try the testing branch, please proceed like that. To try the testing branch, please proceed like that.
```
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug
or or
sudo yunohost app upgrade aeneria -u https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug sudo yunohost app upgrade aeneria -u https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug
``` ```
**More info regarding app packaging:** https://yunohost.org/packaging_apps **More info regarding app packaging:** <https://yunohost.org/packaging_apps>

View file

@ -1,10 +1,14 @@
<!--
N.B.: This README was automatically generated by https://github.com/YunoHost/apps/tree/master/tools/README-generator
It shall NOT be edited by hand.
-->
# æneria pour YunoHost # æneria pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg) [![Niveau d'intégration](https://dash.yunohost.org/integration/aeneria.svg)](https://dash.yunohost.org/appci/app/aeneria) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/aeneria.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/aeneria.maintain.svg)
[![Installer æneria avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=aeneria) [![Installer æneria avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=aeneria)
*[Read this readme in english.](./README.md)* *[Read this readme in english.](./README.md)*
*[Lire ce readme en français.](./README_fr.md)*
> *Ce package vous permet d'installer æneria rapidement et simplement sur un serveur YunoHost. > *Ce package vous permet d'installer æneria rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.*
@ -19,11 +23,9 @@ The idea of [æneria](https://aeneria.com) is to display energy consumption and
**Version incluse :** 1.1.6~ynh2 **Version incluse :** 1.1.6~ynh2
## Captures d'écran ## Captures d'écran
![](./doc/screenshots/screenshot1.png) ![Capture d'écran de æneria](./doc/screenshots/screenshot1.png)
## Avertissements / informations importantes ## Avertissements / informations importantes
@ -44,21 +46,22 @@ But don't worry, you can easilly transfer your data from Pilea to æneria follow
## Documentations et ressources ## Documentations et ressources
* Site officiel de l'app : https://aeneria.com * Site officiel de l'app : <https://aeneria.com>
* Documentation officielle de l'admin : https://docs.aeneria.com * Documentation officielle de l'admin : <https://docs.aeneria.com>
* Dépôt de code officiel de l'app : https://gitlab.com/aeneria/aeneria-app * Dépôt de code officiel de l'app : <https://gitlab.com/aeneria/aeneria-app>
* Documentation YunoHost pour cette app : https://yunohost.org/app_aeneria * Documentation YunoHost pour cette app : <https://yunohost.org/app_aeneria>
* Signaler un bug : https://github.com/YunoHost-Apps/aeneria_ynh/issues * Signaler un bug : <https://github.com/YunoHost-Apps/aeneria_ynh/issues>
## Informations pour les développeurs ## Informations pour les développeurs
Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing). Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing).
Pour essayer la branche testing, procédez comme suit. Pour essayer la branche testing, procédez comme suit.
```
``` bash
sudo yunohost app install https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug sudo yunohost app install https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug
ou ou
sudo yunohost app upgrade aeneria -u https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug sudo yunohost app upgrade aeneria -u https://github.com/YunoHost-Apps/aeneria_ynh/tree/testing --debug
``` ```
**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps **Plus d'infos sur le packaging d'applications :** <https://yunohost.org/packaging_apps>

View file

@ -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

View file

@ -12,6 +12,21 @@ pkg_dependencies="apt-transport-https postgresql postgresql-contrib php${YNH_PHP
# PERSONAL HELPERS # PERSONAL HELPERS
#================================================= #=================================================
# Assign two variables:
# minutes: random value between 00 and 59 (MM)
# hour: random value between 0 and 2
# To avoid peak load on proxy.aeneria.com, we randomize when the cron job will be launched
# Assign two variables:
# minutes: random value between 00 and 59 (MM)
# hour: random value between 0 and 2
# These two variables are used in conf/aeneria.cron 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 # EXPERIMENTAL HELPERS
#================================================= #=================================================

View file

@ -149,6 +149,9 @@ popd
#================================================= #=================================================
ynh_script_progression --message="Setuping a cron..." --weight=1 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" ynh_add_config --template="../conf/aeneria.cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app" chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app"

View file

@ -25,6 +25,8 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
deskey=$(ynh_app_setting_get --app=$app --key=deskey) deskey=$(ynh_app_setting_get --app=$app --key=deskey)
db_user="$db_name" db_user="$db_name"
hour=$(ynh_app_setting_get --app=$app --key=hour)
minutes=$(ynh_app_setting_get --app=$app --key=minutes)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
@ -66,6 +68,12 @@ if [ -z "$final_path" ]; then
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi 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 # Cleaning legacy permissions
if ynh_legacy_permissions_exists; then if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all ynh_legacy_permissions_delete_all