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

Add Filesystem as a backend for CeleryManager in background callbacks #3116

Open
celia-lm opened this issue Jan 3, 2025 · 0 comments
Open
Labels
cs customer success feature something new P2 considered for next cycle

Comments

@celia-lm
Copy link

celia-lm commented Jan 3, 2025

How is this feature useful?

  • When the value that the background callback returns is bigger than 512MB (formatted as a string), an error will be raised: celery.exceptions.BackendStoreError: value too large for Redis backend
  • This error occurs because the CeleryManager temporarily stores the output value of the background callback.
  • A workaround for this could be using a FilesystemBackend (for example, the DE5 Persistent Filesystem), like this:
celery_app = Celery(__name__, broker=os.environ['REDIS_URL'], backend='../mount')
background_callback_manager = CeleryManager(celery_app)

What's the current state?

  • In the CeleryManager for background callbacks, the values are stored as strings (ref code: link).
  • When the backend is a filesystem, celery (as a dependency of the CeleryManager) expects the format to be bytes (ref: link).
  • The current version of dash CeleryManager for background callbacks doesn't contemplate the case where the backend is a filesystem; it assumes Redis will be used as a backend (ref: link).
  • Celery does contemplate the option os using a FilesystemBackend (ref link, but the CeleryManager doesn't know how to handle that situation.

What changes would be necessary?

  • In places where cache.set(progress_key, json.dumps(progress_value, cls=PlotlyJSONEncoder)) is used directly add a conditional logic to support both RedisBackend and FilesystemBackend like:
from kombu.utils.encoding import str_to_bytes [[source]](https://docs.celeryq.dev/projects/kombu/en/latest/_modules/kombu/utils/encoding.html#str_to_bytes)
...

if isinstance(celery_app.backend, RedisBackend):
    cache.set(progress_key, json.dumps(progress_value, cls=PlotlyJSONEncoder))
elif isinstance(celery_app.backend, FilesystemBackend):
    celery_app.backend.set(progress_key, str_to_bytes(json.dumps(progress_value(progress_value)))
    # ref: https://github.com/celery/celery/blob/main/celery/backends/filesystem.py#L87
@gvwilson gvwilson added feature something new P2 considered for next cycle cs customer success labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cs customer success feature something new P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

2 participants