Skip to content

Commit

Permalink
perf: rebuild website search index in background (backport #17974) (#…
Browse files Browse the repository at this point in the history
…20335)

* perf: rebuild website search index in background (#17974)

* perf: rebuild website search index in background

* refactor: allow enqueueing jobs during migrate

This was added a long time ago to handle missing redis during migrate.
It is not the case right now as redis HAS to be availabe during
migration.

ref: #2988

* ci: pass correct build type

* chore: warn about redis unavailability

(cherry picked from commit fbee80f)

# Conflicts:
#	.github/workflows/ui-tests.yml
#	frappe/utils/background_jobs.py

* chore: conflicts

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Mar 14, 2023
1 parent a27178d commit c1b0210
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions frappe/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def tearDown(self):
json.dump(list(frappe.flags.touched_tables), f, sort_keys=True, indent=4)

if not self.skip_search_index:
print(f"Building search index for {frappe.local.site}")
build_index_for_all_routes()
print(f"Queued rebuilding of search index for {frappe.local.site}")
frappe.enqueue(build_index_for_all_routes, queue="long")

frappe.publish_realtime("version-update")
frappe.flags.touched_tables.clear()
Expand Down
10 changes: 8 additions & 2 deletions frappe/utils/background_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ def enqueue(
)
)

call_directly = now or frappe.flags.in_migrate or (not is_async and not frappe.flags.in_test)
call_directly = now or (not is_async and not frappe.flags.in_test)
if call_directly:
return frappe.call(method, **kwargs)

q = get_queue(queue, is_async=is_async)
try:
q = get_queue(queue, is_async=is_async)
except ConnectionError:
# If redis is not available for queueing execute the job directly
print(f"Redis queue is unreachable: Executing {method} synchronously")
return frappe.call(method, **kwargs)

if not timeout:
timeout = get_queues_timeout().get(queue) or 300
queue_args = {
Expand Down

0 comments on commit c1b0210

Please sign in to comment.