Add missing elasticsearch_indexing checks to workers
What does this MR do and why?
This MR adds missing checks for workers that require elasticsearch_indexing to be enabled. If the setting gets turned off between when a job is queued and the worker is processed, the worker should return early
AI Summary
This code change adds safety checks to two background workers that handle Elasticsearch search functionality when projects are transferred or deleted.
The main improvement is that both workers now check if Elasticsearch indexing is enabled before doing any work - if it's disabled, they simply exit early and do nothing. This prevents unnecessary processing when the search feature isn't being used.
The code also includes some minor formatting cleanup, like reorganizing import statements and fixing indentation.
The test files were updated to verify this new behavior works correctly - they now test both scenarios where Elasticsearch is enabled (existing functionality continues to work) and disabled (workers do nothing). The tests were also restructured to be more organized, grouping related test cases together under clear headings.
This is a defensive programming improvement that makes the system more efficient by avoiding pointless work when search indexing is turned off, while ensuring all existing functionality remains intact when it is enabled.
References
Found while working on a related MR: Add pause_control to Elastic delete workers (!198615 - merged)
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
- setup gdk to have advanced search turned off, you can do via:
- Admin UI - Search - Advanced search - uncheck
Elasticsearch indexing
- Admin UI - Search - Advanced search - uncheck
- run both of the workers from the console, ensure they do not do anything.
- you can monitor the
log/elasticsearch.logfile in gdk to make sure no indexing is attempted
Elastic::ProjectTransferWorker.new.perform(1, 1, 2)
...
ElasticDeleteProjectWorker.new.perform(1, "project_1")
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.