How to use the command 'pueue add' (with examples)
“Pueue” is a command-line task management tool that allows users to enqueue and manage commands for later execution. The pueue add
command provides flexibility in how tasks are managed, including task prioritization, grouping, scheduling, and more. This article illustrates several use cases, demonstrating the power and versatility of pueue add
in automating and organizing command execution.
Add any command to the default queue
Code:
pueue add command
Motivation:
This is one of the simplest use cases for the pueue add
command. When you just need to add a task to the queue without any additional parameters or special handling, this approach quickly places the task into the default processing queue. It’s a straightforward way to execute any command whenever you are handling numerous tasks which can safely be processed in default order. For busy terminals with numerous tasks, automatic queuing ensures smooth task handling without manual time tracking.
Explanation:
pueue add
: Initiates the command-adding functionality ofpueue
.command
: This represents any shell command you wish to execute later. It is a placeholder for actual commands likels
,echo
, etc.
Example output:
Task 1 has been added with command `command`.
Pass a list of flags or arguments to a command when enqueuing
Code:
pueue add -- command --arg -f
Motivation:
Commands often require multiple options or flags to specify their behavior. This use case illustrates enqueuing a command that requires careful setting of arguments and flags. It’s particularly useful when dealing with utilities needing detailed configuration or complex options.
Explanation:
--
: Indicates that anything following it should be treated as part of the command being enqueued. It allows the command to interpret its particular flags correctly.command --arg -f
: The command followed by its specific flags and arguments. This layout ensurescommand
receives the intended options for execution.
Example output:
Task 2 has been added with command `command --arg -f`.
Add a command but do not start it if it’s the first in a queue
Code:
pueue add --stashed -- rsync --archive --compress /local/directory /remote/directory
Motivation:
There are scenarios in which you might want to prepare a task without executing it immediately, such as when ensuring dependencies are in place or manually starting tasks when external conditions are met. Using the --stashed
option provides control over when and whether the task starts.
Explanation:
--stashed
: Directspueue
to add the task in a dormant state, meaning it won’t start automatically even if it’s first in line.rsync --archive --compress /local/directory /remote/directory
: An example of a command meant to synchronize files between directories, with flags to archive and compress during transmission.
Example output:
Task 3 (Stashed): `rsync --archive --compress /local/directory /remote/directory`.
Add a command to a group and start it immediately
Code:
pueue add --immediate --group "CPU_intensive" -- ffmpeg -i input.mp4 frame_%d.png
Motivation:
When executing tasks with significant CPU demands, it can be advantageous to group them. Grouping allows you to manage resources effectively and ensures that tasks are treated according to their resource needs. Using --immediate
ensures the task is prioritized for execution, essential for urgent or resource-intensive processes like video conversion.
Explanation:
--immediate
: Starts the task right after adding it; doesn’t wait for other tasks to finish.--group "CPU_intensive"
: This assigns the task to the “CPU_intensive” group, facilitating resource management by clustering similar tasks.ffmpeg -i input.mp4 frame_%d.png
: A command to convert a video file into sequential image frames.
Example output:
Task 4 added to the group "CPU_intensive" and started immediately: `ffmpeg -i input.mp4 frame_%d.png`.
Add a command and start it after commands 9 and 12 finish successfully
Code:
pueue add --after 9 12 --group "torrents" -- transmission-cli torrent_file.torrent
Motivation:
Some tasks can only be initiated once others have completed, necessitating sequential execution. Whether you are dependent on download completions or need to comply with your system’s workflow, --after
provides necessary constraints to avoid premature commencements.
Explanation:
--after 9 12
: Specifies the task should only start once tasks 9 and 12 are finished successfully.--group "torrents"
: Assigns the task to the “torrents” group for targeted processing.transmission-cli torrent_file.torrent
: A command for downloading a torrent file.
Example output:
Task 5 will be started after tasks 9 and 12 are completed: `transmission-cli torrent_file.torrent`.
Add a command with a label after some delay has passed
Code:
pueue add --label "compressing large file" --delay "wednesday 10:30pm" -- "7z a compressed_file.7z large_file.xml"
Motivation:
Task scheduling is fundamental in scenarios requiring specific timing coordination. By applying a delay to task execution, users can align operations with availability or off-peak periods, optimizing execution for systems based on planned downtime or increased demand prediction.
Explanation:
--label "compressing large file"
: Assigns a descriptive label to the task, making searchability and identification easier in the queue.--delay "wednesday 10:30pm"
: Sets a precise activation time for the task.7z a compressed_file.7z large_file.xml
: Command to compress a large XML file into a 7z archive.
Example output:
Task 6 labeled "compressing large file" scheduled for Wednesday 10:30pm: `7z a compressed_file.7z large_file.xml`.
Conclusion:
The pueue add
command is a versatile tool in any command-line user’s toolkit, offering granular control over task scheduling and execution. With support for task grouping, scheduling, and complex command execution setups, pueue add
empowers users to efficiently manage serial task execution in diverse computing environments. By utilizing its many options, command-line tasks can be seamlessly integrated into workflows, enhancing productivity and automation.