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

[Bug] Changing PRUNE_RESULTS_OLDER_THAN value doesn't have any effect #2006

Closed
armond-avanes opened this issue Jan 20, 2025 · 12 comments · Fixed by #2025
Closed

[Bug] Changing PRUNE_RESULTS_OLDER_THAN value doesn't have any effect #2006

armond-avanes opened this issue Jan 20, 2025 · 12 comments · Fixed by #2025
Assignees
Labels
🐛 bug Something isn't working

Comments

@armond-avanes
Copy link

armond-avanes commented Jan 20, 2025

Describe the bug
When I decrease the value of PRUNE_RESULTS_OLDER_THAN environment variable from 180 to 90 (days), it doesn't prune my result history. I've been waiting for two days for this process to happen, because I thought it might have been scheduled for a specific time of the day to be executed.

To Reproduce
Steps to reproduce the behavior:

  1. Stop the running docker container
  2. Decrease PRUNE_RESULTS_OLDER_THAN to a lower value
  3. Start the container

Expected behavior
To prune my result history according to the current value of PRUNE_RESULTS_OLDER_THAN.

Environment (please complete the following information):

  • OS: Raspberry OS
  • Architecture: arm64
  • Browser: Chrome
  • Version: 1.2.0

Additional context
I've searched the settings table in the database and I couldn't find any prune_results_older_than record there. So looks like there is only one source of truth for this setting and that's the environment variable.

@svenvg93
Copy link
Contributor

Did it work when you used 180?

@armond-avanes
Copy link
Author

Good point! I checked my results and my oldest one goes back to June 8 which is more than 7 months old. Does this mean the feature is not working at all regardless of the settings? It's a long time I've been maintaining the exact same instance with the same database, etc and only been auto-updated with WatchTower. Could it be because of an older version corrupted the settings?

@svenvg93
Copy link
Contributor

When I run the command manual it all works as intended. Can you share your docker compose.

@armond-avanes
Copy link
Author

armond-avanes commented Jan 20, 2025

I have automated my docker apps [un]installations using Ansible, so there is no docker compose file and I'm running the database in a separate docker container. Here is what I have for docker container installation for SpeedTest-Tracker only:

(the variables are replaced by Ansible by their corresponding values)

- name: Install and run docker container
  docker_container:
    name: "{{ docker_speedtest_tracker_container_name }}"
    image: "{{ docker_speedtest_tracker_image_name }}"
    restart_policy: unless-stopped
    published_ports:
      - "{{ docker_speedtest_tracker_exposed_http_port }}:{{ docker_speedtest_tracker_internal_http_port }}"
      - "{{ docker_speedtest_tracker_exposed_https_port }}:{{ docker_speedtest_tracker_internal_https_port }}"
    volumes:
      - "{{ docker_speedtest_tracker_directory }}/config:/config"
      - "{{ ssl_certificates_directory }}/host.crt:/etc/ssl/web/ssl.crt:ro"
      - "{{ ssl_certificates_directory }}/host-pk.pem:/etc/ssl/web/ssl.key:ro"
    env_file: "{{ docker_speedtest_tracker_directory }}/docker-app.env"
    state: started
    container_default_behavior: compatibility
    detach: yes

... and the docker-app.env template file:

PUID=1000
PGID=1000
TZ={{ rpi_timezone }}

APP_NAME=HomeLab - Speedtest Tracker
APP_URL=https://{{ ansible_host }}:{{ docker_speedtest_tracker_exposed_https_port }}
APP_KEY={{ docker_speedtest_tracker_secret_key }}
APP_DEBUG=false
APP_TIMEZONE={{ rpi_timezone }}
APP_LOCALE=en
APP_FALLBACK_LOCALE=en

PUBLIC_DASHBOARD=true
SPEEDTEST_SCHEDULE=8-59/15 * * * *
SPEEDTEST_SERVERS=57682,60433,61417,52311,33893,52470,14236,12191,9916,34840,7190,50081,21001,19230,21541,35056,5861
DISPLAY_TIMEZONE={{ rpi_timezone }}
PRUNE_RESULTS_OLDER_THAN=90

DB_CONNECTION=mysql
DB_HOST={{ mariadb_host_ip }}
DB_PORT={{ docker_mariadb_exposed_port }}
DB_DATABASE={{ docker_speedtest_tracker_database_name }}
DB_USERNAME={{ docker_speedtest_tracker_database_user }}
DB_PASSWORD={{ docker_speedtest_tracker_database_password }}

If you need to know the actual value of a particular variable or a setting/record in the database, please let me know and I will post them here.

By the way, what's the cron schedule for pruning the results history? Is it calculated from the container up time? I don't see any cron schedule variable in the env variables.

@svenvg93
Copy link
Contributor

By the way, what's the cron schedule for pruning the results history? Is it calculated from the container up time? I don't see any cron schedule variable in the env variables.

It's using the laravel task scheduler for it. It should run every day at midnight.

Might have an idea why it does not run but I need to double check with Alex, before I say anything stupid.

@alexjustesen
Copy link
Owner

Just to confirm since it's behind a config you're using the LSIO image right?

@armond-avanes
Copy link
Author

Just to confirm since it's behind a config you're using the LSIO image right?

Yes, right.

@alexjustesen
Copy link
Owner

@armond-avanes if you run php artisan model:prune --pretend what do you get as a response?

@armond-avanes
Copy link
Author

@armond-avanes if you run php artisan model:prune --pretend what do you get as a response?

So I logged into my SpeedTest-Tracker container using Portainer and executed the above line. Here is the error I got back:
Could not open input file: artisan

@svenvg93
Copy link
Contributor

svenvg93 commented Feb 1, 2025

You need to be in the /app/www/ folder for that one 😉

@armond-avanes
Copy link
Author

You need to be in the /app/www/ folder for that one 😉

Thanks for the clarification. I switched to that folder and executed the command. Here is the new error stack trace:

[2025-02-01 08:18:51] production.ERROR: A non-numeric value encountered {"exception":"[object] (ErrorException(code: 0): A non-numeric value encountered at /app/www/vendor/nesbot/carbon/src/Carbon/Traits/Units.php:379)
[stacktrace]
#0 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(290): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 /app/www/vendor/nesbot/carbon/src/Carbon/Traits/Units.php(379): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()
#2 /app/www/vendor/nesbot/carbon/src/Carbon/Traits/Date.php(2903): Carbon\\Carbon->subUnit()
#3 /app/www/vendor/nesbot/carbon/src/Carbon/Traits/Date.php(2594): Carbon\\Carbon->callModifierMethod()
#4 /app/www/app/Models/Result.php(46): Carbon\\Carbon->__call()
#5 /app/www/vendor/laravel/framework/src/Illuminate/Database/Console/PruneCommand.php(191): App\\Models\\Result->prunable()
#6 /app/www/vendor/laravel/framework/src/Illuminate/Database/Console/PruneCommand.php(59): Illuminate\\Database\\Console\\PruneCommand->pretendToPrune()
#7 /app/www/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(259): Illuminate\\Database\\Console\\PruneCommand->Illuminate\\Database\\Console\\{closure}()
#8 /app/www/vendor/laravel/framework/src/Illuminate/Database/Console/PruneCommand.php(58): Illuminate\\Support\\Collection->each()
#9 /app/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Database\\Console\\PruneCommand->handle()
#10 /app/www/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#11 /app/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure()
#12 /app/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#13 /app/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(694): Illuminate\\Container\\BoundMethod::call()
#14 /app/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\\Container\\Container->call()
#15 /app/www/vendor/symfony/console/Command/Command.php(279): Illuminate\\Console\\Command->execute()
#16 /app/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\\Component\\Console\\Command\\Command->run()
#17 /app/www/vendor/symfony/console/Application.php(1094): Illuminate\\Console\\Command->run()
#18 /app/www/vendor/symfony/console/Application.php(342): Symfony\\Component\\Console\\Application->doRunCommand()
#19 /app/www/vendor/symfony/console/Application.php(193): Symfony\\Component\\Console\\Application->doRun()
#20 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(198): Symfony\\Component\\Console\\Application->run()
#21 /app/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1208): Illuminate\\Foundation\\Console\\Kernel->handle()
#22 /app/www/artisan(13): Illuminate\\Foundation\\Application->handleCommand()
#23 {main}
"} 

In Units.php line 379:
                                   
  A non-numeric value encountered 

@alexjustesen
Copy link
Owner

Alrighty... Now we're getting somewhere. I'll put a patch together to always cast the value as an integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants