Hannes221 / rq-dashboard-fast

Redis Queue Dashboard based on FastAPI
MIT License
86 stars 8 forks source link

/jobs fails with 500 #84

Closed rbange closed 5 months ago

rbange commented 5 months ago
{"event": "127.0.0.1:54985 - \"GET /dashboard/jobs HTTP/1.1\" 500", "logger": "uvicorn.access", "level": "info"}
{"event": "Exception in ASGI application\n", "exc_info": ["<class 'ValueError'>", "ValueError(\"invalid literal for int() with base 10: 'An error occurred reading jobs data template:'\")", "<traceback object at 0x1402ff100>"], "logger": "uvicorn.error", "level": "error"}
--- Logging error ---
Traceback (most recent call last):
  File "mydir/.venv/lib/python3.12/site-packages/rq_dashboard_fast/rq_dashboard_fast.py", line 170, in read_jobs
    return self.templates.TemplateResponse(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/starlette/templating.py", line 230, in TemplateResponse
    return _TemplateResponse(
           ^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/starlette/templating.py", line 40, in __init__
    content = template.render(context)
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "mydir/.venv/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "mydir/.venv/lib/python3.12/site-packages/rq_dashboard_fast/templates/jobs.html", line 1, in top-level template code
    {% extends "base.html" %}{% block content %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/rq_dashboard_fast/templates/base.html", line 16, in top-level template code
    <div>{% block content %}{% endblock %}</div>
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/rq_dashboard_fast/templates/jobs.html", line 258, in block 'content'
    <a href="{{ url_for('get_job_data', job_id=job.id) }}"
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/starlette/templating.py", line 138, in url_for
    return request.url_for(name, **path_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/starlette/requests.py", line 187, in url_for
    url_path = router.url_path_for(name, **path_params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 703, in url_path_for
    raise NoMatchFound(name, path_params)
starlette.routing.NoMatchFound: No route exists for name "get_job_data" and params "job_id".

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/logging/__init__.py", line 1160, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/logging/__init__.py", line 999, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/logging/__init__.py", line 703, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/logging/__init__.py", line 392, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
TypeError: not all arguments converted during string formatting
Call stack:
  File "<string>", line 1, in <module>
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/multiprocessing/spawn.py", line 122, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/multiprocessing/spawn.py", line 135, in _main
    return self._bootstrap(parent_sentinel)
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "mydir/.venv/lib/python3.12/site-packages/uvicorn/_subprocess.py", line 78, in subprocess_started
    target(sockets=sockets)
  File "mydir/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 62, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
  File "/Users/myuser/.pyenv/versions/3.12.3/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "mydir/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "mydir/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 758, in __call__
    await self.middleware_stack(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 778, in app
    await route.handle(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 487, in handle
    await self.app(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 758, in __call__
    await self.middleware_stack(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 778, in app
    await route.handle(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 299, in handle
    await self.app(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 79, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "mydir/.venv/lib/python3.12/site-packages/starlette/routing.py", line 74, in app
    response = await func(request)
  File "mydir/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 294, in app
    raw_response = await run_endpoint_function(
  File "mydir/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
  File "mydir/.venv/lib/python3.12/site-packages/rq_dashboard_fast/rq_dashboard_fast.py", line 182, in read_jobs
    logger.exception("An error occurred reading jobs data template:", e)
Message: 'An error occurred reading jobs data template:'
Arguments: (NoMatchFound('No route exists for name "get_job_data" and params "job_id".'),)
{"event": "127.0.0.1:54992 - \"GET /dashboard/jobs HTTP/1.1\" 500", "logger": "uvicorn.access", "level": "info"}

My implementation:

dashboard = RedisQueueDashboard(
        redis_url=f"redis://{settings.redis_host}:{settings.redis_port}/",
        prefix="/dashboard",
    )
app.mount(
    "/dashboard", app=dashboard, name="RQ Dashboard"
)
dtomas1989 commented 3 months ago

Hello @Hannes221, I see that the issue is completed but I am having the same error using the latest version (https://pypi.org/project/rq-dashboard-fast/0.5.2/). Do you think I should add some modification to my code or use another version?

My code looks like this:

# RQ-Dashboard
redis_url = f"redis://{REDIS_HOST}:{REDIS_PORT}/"
dashboard = RedisQueueDashboard(redis_url, "/rq")
app.mount("/rq", dashboard)

Note: The rest of the tabs work fine, only the error appears in "/jobs"

Thanks in advance

Hannes221 commented 3 months ago

Hi, @dtomas1989. I am not able to replicate the problem with your setup. Can you share the error message with me?

dtomas1989 commented 3 months ago

Hello @Hannes221, the error in the browser looks like this: Screenshot 2024-08-05 at 09 50 19

As I mentioned before, the error only appears in "/jobs" the rest of the tabs work fine.

And the error from the console is:

File "/usr/local/lib/python3.12/site-packages/rq_dashboard_fast/utils/jobs.py", line 198, in get_jobs
logger.exception("Error fetching job data: ", error)
Message: 'Error fetching job data: '
Arguments: (TypeError("str() argument 'encoding' must be str, not AttributeError"),)
logger.exception("An error occurred reading jobs data template:", e)
status_code=500, detail=str("Error fetching job data: ", error)

Thanks in advance

Hannes221 commented 3 months ago

Could you try again with the newest release and send me the error message? Thank you!

dtomas1989 commented 3 months ago

Hi @Hannes221, this is the error using the newest release (https://pypi.org/project/rq-dashboard-fast/0.5.4/):

File "/usr/local/lib/python3.12/site-packages/rq_dashboard_fast/utils/jobs.py", line 120, in get_job_registrys
status = job.get_status()
AttributeError: 'NoneType' object has no attribute 'get_status'

Thanks to you!

dtomas1989 commented 3 months ago

Hello @Hannes221 , I've already solved the problem. For some reason I was getting a job like None in the job list (https://github.com/Hannes221/rq-dashboard-fast/blob/main/rq_dashboard_fast/utils/jobs.py#L120). Adding the following line works (as a temporary solution to verify the error).

if job is None:
    continue

I will investigate why that job came to me as None from the database.

Thanks for your help

Hannes221 commented 3 months ago

Thank you @dtomas1989. This should be resolved in the newest release.