Nukesor / pueue

:stars: Manage your shell commands.
MIT License
4.68k stars 128 forks source link

[Bug] Limiting status output falsly claims "Task list is empty" #508

Closed Cook-I-T closed 3 months ago

Cook-I-T commented 3 months ago

Describe the bug

I tried to check in a Bash script if there's still a task running in a certain group with the bash command pueue status -g group columns=Status status=running first 1 | grep 'Running' | wc -l I expect that when a group still has any running task it outputs one row of "Running" which gets converted to a 1, with nothing running outputting 0.

Steps to reproduce

cookit@cook-pc:~$ pueue group add g1
Group "g1" is being created
cookit@cook-pc:~$ pueue group add g2
Group "g2" is being created
cookit@cook-pc:~$ pueue add -g g1 sleep 60
New task added (id 0).
cookit@cook-pc:~$ pueue add -g g1 sleep 60
New task added (id 1).
cookit@cook-pc:~$ pueue add -g g1 sleep 60
New task added (id 2).
cookit@cook-pc:~$ pueue add -g g2 sleep 60
New task added (id 3).
cookit@cook-pc:~$ pueue add -g g2 sleep 60
New task added (id 4).
cookit@cook-pc:~$ pueue add -g g2 sleep 60
New task added (id 5).
cookit@cook-pc:~$ pueue status -g g1 columns=Status status=running first 1
Group "g1" (1 parallel): running
─────────
 Status  
═════════
 Running 
─────────
cookit@cook-pc:~$ pueue status -g g2 columns=Status status=running first 1
Group "g2" (1 parallel): running
Task list is empty. Add tasks with `pueue add -g g2 -- [cmd]`
cookit@cook-pc:~$ pueue
Group "g1" (1 parallel): running
─────────────────────────────────────────────────────────
 Id   Status    Command    Path           Start      End 
═════════════════════════════════════════════════════════
 0    Running   sleep 60   /home/cookit   20:56:15       
─────────────────────────────────────────────────────────
 1    Queued    sleep 60   /home/cookit                  
─────────────────────────────────────────────────────────
 2    Queued    sleep 60   /home/cookit                  
─────────────────────────────────────────────────────────

Group "g2" (1 parallel): running
─────────────────────────────────────────────────────────
 Id   Status    Command    Path           Start      End 
═════════════════════════════════════════════════════════
 3    Running   sleep 60   /home/cookit   20:56:20       
─────────────────────────────────────────────────────────
 4    Queued    sleep 60   /home/cookit                  
─────────────────────────────────────────────────────────
 5    Queued    sleep 60   /home/cookit                  
─────────────────────────────────────────────────────────
cookit@cook-pc:~$ pueue status -g g2 columns=Status status=running first 1
Group "g2" (1 parallel): running
Task list is empty. Add tasks with `pueue add -g g2 -- [cmd]`
cookit@cook-pc:~$ pueue status -g g1 columns=Status status=running first 1
Group "g1" (1 parallel): running
─────────
 Status  
═════════
 Running 
─────────

Debug logs (if relevant)

cookit@cook-pc:~$ pueue -vvv status -g g1 columns=Status status=running first 1
21:01:02 [INFO] Parsing config files
21:01:02 [INFO] Checking path: "/home/cookit/.config/pueue/pueue.yml"
21:01:02 [INFO] Found config file at: "/home/cookit/.config/pueue/pueue.yml"
21:01:02 [DEBUG] (1) pueue_lib::network::protocol: Sending message: Status
21:01:02 [DEBUG] (1) pueue_lib::network::protocol: Received message: StatusResponse(
    State {
        tasks: {
            0: Task {
                id: 0,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g1",
                dependencies: [],
                label: None,
                status: Running,
                prev_status: Locked,
                start: Some(
                    2024-03-12T21:00:37.595571177+01:00,
                ),
                end: None,
            },
            1: Task {
                id: 1,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g1",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
            2: Task {
                id: 2,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g1",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
            3: Task {
                id: 3,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g2",
                dependencies: [],
                label: None,
                status: Running,
                prev_status: Locked,
                start: Some(
                    2024-03-12T21:00:43.598473578+01:00,
                ),
                end: None,
            },
            4: Task {
                id: 4,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g2",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
            5: Task {
                id: 5,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g2",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
        },
        groups: {
            "default": Group {
                status: Running,
                parallel_tasks: 1,
            },
            "g1": Group {
                status: Running,
                parallel_tasks: 1,
            },
            "g2": Group {
                status: Running,
                parallel_tasks: 1,
            },
        },
    },
)
Group "g1" (1 parallel): running
─────────
 Status  
═════════
 Running 
─────────
cookit@cook-pc:~$ pueue -vvv status -g g2 columns=Status status=running first 1
21:01:14 [INFO] Parsing config files
21:01:14 [INFO] Checking path: "/home/cookit/.config/pueue/pueue.yml"
21:01:14 [INFO] Found config file at: "/home/cookit/.config/pueue/pueue.yml"
21:01:14 [DEBUG] (1) pueue_lib::network::protocol: Sending message: Status
21:01:14 [DEBUG] (1) pueue_lib::network::protocol: Received message: StatusResponse(
    State {
        tasks: {
            0: Task {
                id: 0,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g1",
                dependencies: [],
                label: None,
                status: Running,
                prev_status: Locked,
                start: Some(
                    2024-03-12T21:00:37.595571177+01:00,
                ),
                end: None,
            },
            1: Task {
                id: 1,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g1",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
            2: Task {
                id: 2,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g1",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
            3: Task {
                id: 3,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g2",
                dependencies: [],
                label: None,
                status: Running,
                prev_status: Locked,
                start: Some(
                    2024-03-12T21:00:43.598473578+01:00,
                ),
                end: None,
            },
            4: Task {
                id: 4,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g2",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
            5: Task {
                id: 5,
                original_command: "sleep 60",
                command: "sleep 60",
                path: "/home/cookit",
                envs: "hidden",
                group: "g2",
                dependencies: [],
                label: None,
                status: Queued,
                prev_status: Locked,
                start: None,
                end: None,
            },
        },
        groups: {
            "default": Group {
                status: Running,
                parallel_tasks: 1,
            },
            "g1": Group {
                status: Running,
                parallel_tasks: 1,
            },
            "g2": Group {
                status: Running,
                parallel_tasks: 1,
            },
        },
    },
)
Group "g2" (1 parallel): running
Task list is empty. Add tasks with `pueue add -g g2 -- [cmd]`
cookit@cook-pc:~$ 

Operating system

Debian 11

Pueue version

3.3.3

Additional context

No response

Nukesor commented 3 months ago

True, that seems to be a bug.

Feel free to investigate and create a PR :) I'm not sure when I have the time to look at this.

Cook-I-T commented 3 months ago

I looked at the code in pueue/src/client/query/ but since I never worked with Rust (and never heard of pest before) I sadly can't help with fixing that bug :( I did figure out that increasing the number somehow makes lines appear again (so for example first 2 shows 1 line of "Running"), but it's not consistent.

For my usecase however I did realise that columns=Status status=running is already limiting the lines of output to the "parallel" count of the group, which makes the magical performance & efficiency I hoped to gain from first 1 kinda irrelevant. I just added a quick head -n 1 after grep and I'm back to the "0 or 1" output I want :) ​ ​ Thanks for developing this amazing tool, if there's a way to support this project outside of PRs I'd gladly help :) Vielen Dank aus Österreich ^_^

Shakil582 commented 3 months ago

submitted a fix here https://github.com/Nukesor/pueue/pull/512

Cook-I-T commented 3 months ago

submitted a fix here #512

Thanks for fixing my bug report! I installed rust, compiled your fork and from what I can see, it fixes the problem :) Now it just requires @Nukesor's approval and another bug is squashed ^_^

Cook-I-T commented 3 months ago

I was just compiling the " fix-group-filtering" branch when it got merged, (again) from what I see it fixes the issue, looking at the changes I again have no idea how it works but it does :) I'm not sure if I should close this issue or not so I'll just leave it...

Thanks again for all the good work! ^_^