Search code examples
redisweb-workervscode-debugger

VS code launch to debug a Redis Queue Worker


I am trying to create a launch configuration on the VS-code so I can debug a Redis Queue background worker.

The existing launch.js contains:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "API",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/src/app/run.py",
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}/src/app"
        }
    ]
}

The commands to launch the Redis Queue worker from a regular bash terminal are:

cd /home/user/api/src/app
source env/bin/activate
rq worker --url redis://localhost:2179

What could be the proper launch.js configuration, so that I can launch and debug the Redis Queue worker using the VS code ?

As of now I ended up to the following:

{
    "name": "Redis Queue Worker",
    "type": "python",
    "request": "launch",
    "program": "rq",
    "console": "integratedTerminal",
    "cwd": "${workspaceFolder}/src/app",
    "args": ["worker", "--url", "redis://localhost:2179"]
}

which gives me the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/home/user/api/src/app/rq'

Solution

  • The accepted answer is misleading. I had a similar problem to debug rq for flask using vscode. I didn't find any answer to this problem on internet except for this accepted answer. The solution I came up with is quite simple, once you understood launch.json

    {
        "configurations": [
            {
                "name": "rq worker",
                "request": "launch",
                "type": "python",
                "program": "${workspaceFolder}/.venv/bin/rq",
                "args": [
                    "worker",
                    "--max-jobs=1"
                ],
                "console": "integratedTerminal",
                "cwd": "${workspaceFolder}/src",
            },
        ],
        "version": "0.2.0"
    }
    

    It simply use the integrated terminal of vscode, which I configured to source my virtual env (.venv) Then it launches rq (providing the full path. YOu may use "which rq" to find your path) with the args "worker --max-jobs=1" to unqueue only one task!

    Thanks to this flask does halt on my breakpoint on the asynchronous part of my flask code