clearcache removes scheduled jobs from redis #8921

Closed
opened 2025-12-29 20:42:52 +01:00 by adam · 5 comments
Owner

Originally created by @abhi1693 on GitHub (Dec 5, 2023).

NetBox version

v3.6.4

Python version

3.10

Steps to Reproduce

  1. Create a report/script and schedule a job for it
  2. Run the clearcache command

Expected Behavior

The scheduled jobs should not be removed from redis or should be readded to redis for the jobs to run again

Observed Behavior

The jobs show on the NetBox UI under /core/jobs/ however, does not show up in /admin/background-tasks/. Moreover, the job will remain in scheduled state forever on the NetBox UI.

Originally created by @abhi1693 on GitHub (Dec 5, 2023). ### NetBox version v3.6.4 ### Python version 3.10 ### Steps to Reproduce 1. Create a report/script and schedule a job for it 2. Run the `clearcache` command ### Expected Behavior The scheduled jobs should not be removed from redis or should be readded to redis for the jobs to run again ### Observed Behavior The jobs show on the NetBox UI under `/core/jobs/` however, does not show up in `/admin/background-tasks/`. Moreover, the job will remain in `scheduled` state forever on the NetBox UI.
adam added the type: bugstatus: under reviewseverity: medium labels 2025-12-29 20:42:52 +01:00
adam closed this issue 2025-12-29 20:42:52 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 5, 2023):

The scheduled jobs should not be removed from redis

But this is the purpose of the clearcache command: To clear out the Redis cache. What is the proposed fix?

@jeremystretch commented on GitHub (Dec 5, 2023): > The scheduled jobs should not be removed from redis But this is the purpose of the `clearcache` command: To clear out the Redis cache. What is the proposed fix?
Author
Owner

@abhi1693 commented on GitHub (Dec 5, 2023):

The jobs that we have scheduled are to be excluded from this clearing. Because this seems unintended as scheduled jobs are not cached objects IMO.

@abhi1693 commented on GitHub (Dec 5, 2023): The jobs that we have scheduled are to be excluded from this clearing. Because this seems unintended as scheduled jobs are not cached objects IMO.
Author
Owner

@jeremystretch commented on GitHub (Dec 5, 2023):

I'm going to propose that we extend the clearcache command with flags to clear specific queues/cache elements. We'll need to do a quick audit to determine what those are. We should also retain the ability to clear the entire cache, but probably implement a confirmation prompt (and maybe stats for sanity checking) to do so.

@jeremystretch commented on GitHub (Dec 5, 2023): ~I'm going to propose that we extend the `clearcache` command with flags to clear specific queues/cache elements. We'll need to do a quick audit to determine what those are. We should also retain the ability to clear the entire cache, but probably implement a confirmation prompt (and maybe stats for sanity checking) to do so.~
Author
Owner

@jeremystretch commented on GitHub (Dec 6, 2023):

I'm not able to reproduce this. After scheduling a script for future execution, I see the queued job appear:

$ redis-cli -n 0 keys "rq:job:*"
1) "rq:job:cc5271f2-c09e-4333-aded-b7463de7a3fd"

Then I run the clearcache management command:

$ ./manage.py clearcache
Cache has been cleared.
Config revision (2) has been restored.

I can confirm that everything from the Django cache has been cleared (except for the config and config revision, which are restored automatically):

$ redis-cli -n 1 keys "*"
1) ":1:config"
2) ":1:config_version"

But the queued job (in database 0) remains as expected:

$ redis-cli -n 0 keys "rq:job:*"
1) "rq:job:cc5271f2-c09e-4333-aded-b7463de7a3fd"

The clearcache command only interacts with the Django cache, calling cache.clear(), which is confined to its own Redis database (REDIS['tasks'] in settings.py), and should never interfere with the RQ database.

@jeremystretch commented on GitHub (Dec 6, 2023): I'm not able to reproduce this. After scheduling a script for future execution, I see the queued job appear: ``` $ redis-cli -n 0 keys "rq:job:*" 1) "rq:job:cc5271f2-c09e-4333-aded-b7463de7a3fd" ``` Then I run the `clearcache` management command: ``` $ ./manage.py clearcache Cache has been cleared. Config revision (2) has been restored. ``` I can confirm that everything from the Django cache has been cleared (except for the config and config revision, which are restored automatically): ``` $ redis-cli -n 1 keys "*" 1) ":1:config" 2) ":1:config_version" ``` But the queued job (in database 0) remains as expected: ``` $ redis-cli -n 0 keys "rq:job:*" 1) "rq:job:cc5271f2-c09e-4333-aded-b7463de7a3fd" ``` The `clearcache` command only interacts with the Django cache, calling `cache.clear()`, which is confined to its own Redis database (`REDIS['tasks']` in `settings.py`), and should never interfere with the RQ database.
Author
Owner

@jeremystretch commented on GitHub (Dec 7, 2023):

I'm going to close this out because, per our discussion, it doesn't seem that clearcache is causing the issue. Additionally, we've decided to remove the clearcache management command in v3.7 (see #14458) in NetBox v3.7 as it is no longer needed.

@jeremystretch commented on GitHub (Dec 7, 2023): I'm going to close this out because, per our discussion, it doesn't seem that `clearcache` is causing the issue. Additionally, we've decided to remove the `clearcache` management command in v3.7 (see #14458) in NetBox v3.7 as it is no longer needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8921