Git Product home page Git Product logo

pueue's Introduction

Pueue

Test Build Crates.io License: MIT Downloads codecov

Pueue

Pueue is a command-line task management tool for sequential and parallel execution of long-running tasks.

Simply put, it's a tool that processes a queue of shell commands. On top of that, there are a lot of convenient features and abstractions.

Since Pueue is not bound to any terminal, you can control your tasks from any terminal on the same machine. The queue will be continuously processed, even if you no longer have any active ssh sessions.

Pueue is considered feature-complete ๐ŸŽ‰. All features that were planned have been added and only minor improvements, bug-fixes and regular maintenance work will get merged.

Features

  • Scheduling
    • Add tasks as you go.
    • Run multiple tasks at once. You decide how many tasks should run concurrently.
    • Change the order of the scheduled tasks.
    • Specify dependencies between tasks.
    • Schedule tasks to run at a specific time.
  • Process interaction
    • Easy output inspection.
    • Send input to running processes.
    • Pause/resume tasks, when you need some processing power right NOW!
  • Task groups (multiple queues)
    • Each group can have several tasks running in parallel.
    • Pause/start tasks by a group.
  • Background process execution
    • The pueued daemon runs in the background. No need to be logged in.
    • Commands are executed in their respective working directories.
    • The current environment variables are copied when adding a task.
    • Commands are run in a shell which allows the full feature set of shell coding.
  • Consistency
    • The queue is always saved to disk and restored on kill/system crash.
    • Logs are persisted onto the disk and survive a crash.
  • Miscellaneous
    • A callback hook to, for instance, set up desktop notifications.
    • JSON output for log and status if you want to display info about tasks in another program.
    • A wait subcommand to wait for specific tasks, a group (or everything) to finish.
  • A lot more. Check the -h options for each subcommand for detailed options.
  • Cross Platform
    • Linux is fully supported and battle-tested.
    • MacOS is fully supported and on par with Linux.
    • Windows is fully supported and working fine for quite a while.
  • Why should I use it
  • Advantages over Using a Terminal Multiplexer

What Pueue is not

Pueue is not designed to be a programmable (scriptable) task scheduler/executor.

The focus of pueue lies on human interaction, i.e. it's supposed to be used by a real person on some kind of OS. See the Design Goals section

Due to this, the feature set of pueue and pueued as well as their implementation and architecture have been kept simple by design! Even though it can be scripted to some degree, it hasn't been built for this and there's no official support!

There's definitely the need for a complex task scheduler/executor with advanced API access and scheduling options, but this is the job for another project, as this is not what pueue has been built for.

Installation

There are a few different ways to install Pueue.

Package Manager

Packaging status

The preferred way to install Pueue is to use your system's package manager. This will usually deploy service files and completions automatically.

Pueue has been packaged for quite a few distributions, check the table on the right for more information.

Prebuild Binaries

Statically linked (if possible) binaries for Linux (incl. ARM), Mac OS and Windows are built on each release.
You can download the binaries for the client and the daemon (pueue and pueued) for each release on the release page.
Just download both binaries for your system, rename them to pueue and pueued and place them in your $PATH/program folder.

Via Cargo

Pueue is built for the current stable Rust version. It might compile on older versions, but this isn't tested or officially supported.

cargo install --locked pueue

This will install Pueue to $CARGO_HOME/bin/pueue (default is ~/.cargo/bin/pueue)

From Source

Pueue is built for the current stable Rust version. It might compile on older versions, but this isn't tested or officially supported.

git clone [email protected]:Nukesor/pueue
cd pueue
cargo build --release --locked --path ./pueue

The final binaries will be located in target/release/{pueue,pueued}.

How to Use it

Check the wiki to get started :).

There are also detailed sections for (hopefully) every important feature:

On top of that, there is a help option (-h) for all commands.

Interact with the Pueue daemon

Usage: pueue [OPTIONS] [COMMAND]

Commands:
  add            Enqueue a task for execution.
                     There're many different options when scheduling a task.
                     Check the individual option help texts for more information.

                     Furthermore, please remember that scheduled commands are executed via your system shell.
                     This means that the command needs proper shell escaping.
                     The safest way to preserve shell escaping is to surround your command with quotes, for example:
                     pueue add 'ls $HOME && echo "Some string"'
  remove         Remove tasks from the list. Running or paused tasks need to be killed first
  switch         Switches the queue position of two commands. Only works on queued and stashed commands
  stash          Stashed tasks won't be automatically started. You have to enqueue them or start them by hand
  enqueue        Enqueue stashed tasks. They'll be handled normally afterwards
  start          Resume operation of specific tasks or groups of tasks.
                     By default, this resumes the default group and all its tasks.
                     Can also be used force-start specific tasks.
  restart        Restart failed or successful task(s).
                     By default, identical tasks will be created and enqueued, but it's possible to restart in-place.
                     You can also edit a few properties, such as the path and the command, before restarting.
  pause          Either pause running tasks or specific groups of tasks.
                     By default, pauses the default group and all its tasks.
                     A paused queue (group) won't start any new tasks.
  kill           Kill specific running tasks or whole task groups..
                     Kills all tasks of the default group when no ids or a specific group are provided.
  send           Send something to a task. Useful for sending confirmations such as 'y\n'
  edit           Edit the command, path or label of a stashed or queued task.
                     By default only the command is edited.
                     Multiple properties can be added in one go.
  group          Use this to add or remove groups.
                     By default, this will simply display all known groups.
  status         Display the current status of all tasks
  format-status  Accept a list or map of JSON pueue tasks via stdin and display it just like "pueue status".
                     A simple example might look like this:
                     pueue status --json | jq -c '.tasks' | pueue format-status
  log            Display the log output of finished tasks.
                     Only the last few lines will be shown by default.
                     If you want to follow the output of a task, please use the "follow" subcommand.
  follow         Follow the output of a currently running task. This command works like "tail -f"
  wait           Wait until tasks are finished.
                     By default, this will wait for all tasks in the default group to finish.
                     Note: This will also wait for all tasks that aren't somehow 'Done'.
                     Includes: [Paused, Stashed, Locked, Queued, ...]
  clean          Remove all finished tasks from the list
  reset          Kill all tasks, clean up afterwards and reset EVERYTHING!
  shutdown       Remotely shut down the daemon. Should only be used if the daemon isn't started by a service manager
  parallel       Set the amount of allowed parallel tasks
                     By default, adjusts the amount of the default group.
                     No tasks will be stopped, if this is lowered.
                     This limit is only considered when tasks are scheduled.
  completions    Generates shell completion files. This can be ignored during normal operations
  help           Print this message or the help of the given subcommand(s)

Options:
  -v, --verbose...         Verbose mode (-v, -vv, -vvv)
      --color <COLOR>      Colorize the output; auto enables color output when connected to a tty [default: auto] [possible values: auto, never, always]
  -c, --config <CONFIG>    If provided, Pueue only uses this config file. This path can also be set via the "PUEUE_CONFIG_PATH" environment variable. The commandline option overwrites the environment variable!
  -p, --profile <PROFILE>  The name of the profile that should be loaded from your config file
  -h, --help               Print help
  -V, --version            Print version

Design Goals

Pueue is designed to be a convenient helper tool for a single user.

It's supposed to work stand-alone and without any external integration. The idea is to keep it simple and to prevent feature creep.

Also, Pueue is considered feature-complete ๐ŸŽ‰. All features that were planned have been added and only minor improvements, bug-fixes and regular maintenance work will get merged.

For the record, the following features weren't included as they're out of scope:

  • Distributed task management/execution.
  • Multi-user task management.
  • Sophisticated task scheduling for optimal load balancing.
  • Tight system integration or integration with external tools.
  • Explicit support for scripting. If you're adamant about scripting it anyway, take a look at the pueue-lib library, which provides proper API calls for pueued. However, keep in mind that pueued is still supposed to be a minimalistic task executor with as little scheduling logic as possible.

There seems to be the need for some project that satisfies all these points mentioned above, but that will be the job of another tool. I very much encourage forking Pueue and I would love to see forks grow into other cool projects!

Similar Projects

slurm

Slurm is a feature rich and widely used cluster management and scheduling system. If you find yourself in the need for complex setups such as multiple worker pools or distributed nodes, slurm will be much better suited than Pueue.

GNU Parallel

A robust and featureful parallel processor with text-based joblog and n-retries. GNU Parallel is able to scale to multi-host parallelization and has complex code to have deep integration across different tools and shells, as well as other advanced features. Pueue differentiates itself from GNU Parallel by focusing more on visibility across many different long running commands, and creating a central location for commands to be stored, rather than GNU Parallel's focus on chunking a specific task.

nq

A very lightweight job queue systems which require no setup, maintenance, supervision, or any long-running processes.
Link to project

task-spooler

task spooler is a Unix batch system where the tasks spooled run one after the other.
Links to ubuntu manpage and a fork on Github. The original website seems to be down.

Contributing

Feature requests and pull requests are very much appreciated and welcome!

Anyhow, please talk to me a bit about your ideas before you start hacking! It's always nice to know what you're working on and I might have a few suggestions or tips :)

Depending on the type of your contribution, you should branch of from the main branch. Pueue is mature enough to no longer need a development branch and all changes are collected on there before a new release is pushed. Urgent hotfixes might get deployed on a separate branch, but this will be decided on a case-by-case basis.

There's also the Architecture Guide, which is supposed to give you a brief overview and introduction to the project.

Copyright ยฉ 2019 Arne Beer (@Nukesor)

pueue's People

Contributors

aeveris avatar banyc avatar chapmanjacobd avatar dadav avatar dependabot-preview[bot] avatar dependabot[bot] avatar dovahcrow avatar drewkett avatar jch-13 avatar jp-ellis avatar kaindljulian avatar lej77 avatar loewenheim avatar mephistophiles avatar mimikun avatar mjpieters avatar nukesor avatar philvince96 avatar printfn avatar quebin31 avatar rycee avatar sh3rm4n avatar skx avatar soruh avatar sourcefrog avatar spyrosroum avatar taylor1791 avatar tinou98 avatar twillingham avatar xunop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pueue's Issues

pueue add -- command

Currently, pueue add requires the command to be in one argument, like pueue add "ls a". It would be handy to be able to do pueue add ls a, and pueue add -- ls -l to pass flags to the command.

Tags and Task grouping

I love the simplicity of pueue so I'm hesitant to ask for this, but I feel it would be really useful.

Scenario:

Multiple long-running jobs queued. Some are IO bound, some CPU bound. I only want one of each to run at any one time, but the only way I can manage this currently is by switching jobs around and tweaking the maxProcesses config value ocassionally.

For example, if I don't check the queue status in time and 2 'CPU jobs' are running and no 'IO jobs', then I switch jobs so that the next job is IO, and set maxProcesses to 3, then immediately back to 2.

Unless there is already a better way to handle this that I'm missing?

Pre-rerunning my env setup script

I tried out pueue today and it works well for base commands like ls, rm, etc.

It uses /bin/sh as the default shell.

But I have an elaborate .cshrc for tcsh shell. Would it be possible to start a tcsh shell instead and then source my shell setup files before pueue tries to run the COMMAND I add using pueue add 'COMMAND'?

Idea: add a switch to specify signal for pueue kill

It's not always desirable to kill via SIGKILL (-9). Some listen for different signals which communicate them different things (think e.g. about dnsmasq, for which pkill -HUP dnsmasq would clear DNS cache).

So I'd say to add -s switch to specify a signal and that switch should accept both numeral and literal signal names, just like a regular kill command:

$ pueue kill -k 1 -s 2
$ pueue kill -k 1 -s INT
$ pueue kill -k 1 -s SIGINT
$ pueue kill -k 1 -s int
$ pueue kill -k 1 -s sigint

In my opinion by default it should be set to TERM, just like for a kill command.

Handle non utf-8 bytes in subprocess output

If there are invalid characters in subprocess outputs, the daemon dies while he tries to parse and log the stdout and stderr output inside the check_finished function.
I'm just trying to reproduce this error and I'll add a stacktrace for later debugging.

pueue kill -k doesn't work

$ pueue status
Daemon: running

 Index  Status   Code  Command     Path                   Start  End
-----------------------------------------------------------------------
 #0     running        make serve  /home/virgo/code/blog  12:09
 #1     done     0     ls          /home/virgo            12:07  12:07

$ pueue kill -k 0
No running process with this key.

However, it does "something", because after running it, the old process is spawned again and process' start time is updated:

$ pueue add "sleep 100"
$ ps aux | ag -i sleep
virgo    21381  0.0  0.0   4336   728 ?        S    12:19   0:00 /bin/sh -c sleep 100
virgo    21382  0.0  0.0   5808   692 ?        S    12:19   0:00 sleep 100
$ pueue status
Daemon: running

 Index  Status   Code  Command     Path                   Start  End
-----------------------------------------------------------------------
 #0     running        sleep 100   /home/virgo/code/blog  12:19

$ pueue kill -k 0
No running process with this key.

$ ps aux | ag -i sleep
virgo    21382  0.0  0.0   5808   692 ?        S    12:19   0:00 sleep 100
virgo    26184  0.0  0.0   4336   728 ?        S    12:20   0:00 /bin/sh -c sleep 100
virgo    26185  0.0  0.0   5808   680 ?        S    12:20   0:00 sleep 100

$ pueue status
Daemon: running

 Index  Status   Code  Command     Path                   Start  End
-----------------------------------------------------------------------
 #0     running        sleep 100   /home/virgo/code/blog  12:20

It clearly shows that parent shell (the one from calling subprocess with shell=True) of sleep command is indeed killed, but shell itself isn't (and new command is spawned, which is another bug in my opinion). Probably that's because the process itself is killed, not the whole process group (os.kill() vs os.killpg()). However, using psutil for process management is more bulletproof so I'd suggest using it instead: http://stackoverflow.com/questions/6549669/how-to-kill-process-and-child-processes-from-python

Arch package error

python-colorclass-git and python-terminaltables-git depend on git python-setuptools. Should be git and python-setuptools.

Feature request - edit

I'm missing the option edit - something like
pueue edit 1 to edit the command in $EDITOR for example

Pause/Start effects subprocess

pueue pause will pause subprocess by default.
Something with:
- os.kill(programID.pid, signal.SIGSTOP)

pueue pause will start subprocess by default.
- os.kill(programID.pid, signal.SIGCONT)

New Option:
pueue pause --wait will wait for subprocess to finish and stop afterwards

Error on checking status: "pickle data was truncated"

The data store appears to be corrupted for my installation of pueue. When I run, $ pueue status, I get this error:

$ pueue status                                                                                                                                         Tue Jun 18 16:50:01 2019
Traceback (most recent call last):
  File "/Users/thopper/.local/bin/pueue", line 11, in <module>
    load_entry_point('pueue==1.0.4', 'console_scripts', 'pueue')()
  File "/Users/thopper/.local/pipx/venvs/pueue/lib/python3.7/site-packages/pueue/__init__.py", line 69, in main
    args.func(args_dict, root_dir)
  File "/Users/thopper/.local/pipx/venvs/pueue/lib/python3.7/site-packages/pueue/client/displaying.py", line 32, in execute_status
    status = command_factory('status')({}, root_dir=root_dir)
  File "/Users/thopper/.local/pipx/venvs/pueue/lib/python3.7/site-packages/pueue/client/factories.py", line 42, in communicate
    response = receive_data(client)
  File "/Users/thopper/.local/pipx/venvs/pueue/lib/python3.7/site-packages/pueue/client/socket.py", line 21, in receive_data
    response = pickle.loads(answer)
_pickle.UnpicklingError: pickle data was truncated

That also kills the pueue process:

2019-06-18 16:52:41,969 - root - ERROR -
Traceback (most recent call last):
  File "/Users/thopper/.local/pipx/venvs/pueue/lib/python3.7/site-packages/pueue/daemon/daemon.py", line 255, in main
    self.respond_client(response, waiting_socket)
  File "/Users/thopper/.local/pipx/venvs/pueue/lib/python3.7/site-packages/pueue/daemon/daemon.py", line 124, in respond_client
    socket.sendall(response)
BlockingIOError: [Errno 35] Resource temporarily unavailable

I'm using Python 3.7.3.

Proper Crypto for remote connections

For now, pueue only supports tcp connections via localhost.

async-tls looks quite promising.
However, we need a way to create new server and client certificates, if they're missing.
I'm still looking for a nice way to do this inside of pueue. I don't want to rely on external (system-specific) libraries and binaries.

pueue clean doesn't work

I use current version from pypi (0.7.4) and it seems that pueue doesn't recognize "clean" subcommand, even though it's listed on pueue --help list.

Here are the steps I performed:

$ pueue --daemon
$ pueue add ls
Command added
$ pueue status
Daemon: running

 Index  Status  Code  Command  Path         Start  End
---------------------------------------------------------
 #0     done    0     ls       /home/virgo  11:28  11:28
$ pueue clean
Unknown Command
$ pueue status
Daemon: running

 Index  Status  Code  Command  Path         Start  End
---------------------------------------------------------
 #0     done    0     ls       /home/virgo  11:28  11:28

Problem starting daemon

When I try to start pueue's daemon I get the following error

$ pueue --daemon
usage: pueue [-h] [--daemon] [--no-daemon] [--stop-daemon] [--root ROOT]
             {status,config,show,log,add,remove,switch,send,reset,clean,pause,start,restart,kill,stop}
             ...
pueue: error: too few arguments

I have the same outcome by running it as --no-daemon.

The installation was done with pip and without sudo, as follows

pip install --user pueue

Let me know if there are other relevant information I can provide.

show --watch incompatible with --key

It appears that whenever using the watch option in pueue show, the output of the same process is always shown, irrespective of the value of --key.

Feature request - ncurses interface

First of all, thank you for this. I've been using pueue because it makes for a nifty way to be more productive. I was wondering if an ncurses interface is a wanted feature. I think it would be awesome, specially if it can get commands by opening the default editor or some tricks like that. It would definitely attract some more stars.

On the other hand, it's kind of unnecessary/bloat and might be a bit lenghty thing to implement. What are your thoughts on this?

`pueue show` when all jobs are finished

After running pueue show without a running command:

Traceback (most recent call last):
  File "/usr/bin/pueue", line 11, in <module>
    load_entry_point('pueue==0.7.3', 'console_scripts', 'pueue')()
  File "/usr/lib/python3.6/site-packages/pueue/__init__.py", line 68, in main
    args.func(args_dict, root_dir)
  File "/usr/lib/python3.6/site-packages/pueue/client/displaying.py", line 148, in execute_show
    stdoutDescriptor = open(stdoutFile, 'r')
FileNotFoundError: [Errno 2] No such file or directory: '/home/yamakaky/.config/pueue/pueue_process_0.stdout'

Unify "log" and "show"

I feel it'd be much more useful if log and show were unified and showed by default the latest log, of either running or finished jobs.

"pip3 install" gives us v1.0.2

I'm not sure bc am not an experienced pueue user (Thank you so much for developing the aewesome app!), but it seems our system stacked because it cannot get result of pueue status.

https://pypi.python.org/pypi/pueue

I am guessing this might have been solved with v1.0.3, so would you update the package on pip repository, please?

807df06

`pueue show --watch --key` not working in tmux

I'm ssh'd into a remote host, in a docker container, and using tmux.

command:

pueue show --watch --key 0

Traceback:

Traceback (most recent call last):
  File "/opt/conda/bin/pueue", line 10, in <module>
    sys.exit(main())
  File "/opt/conda/lib/python3.6/site-packages/pueue/__init__.py", line 69, in main
    args.func(args_dict, root_dir)
  File "/opt/conda/lib/python3.6/site-packages/pueue/client/displaying.py", line 217, in execute_show
    stdscr.addstr(0, 0, message)
_curses.error: addwstr() returned ERR

I'm guessing curses is assuming the size of my terminal or something, but I haven't had the chance to dig in yet.

E:
pueue show --key 0 does not fail, so it's specifically an issue with --watch.

Full Windows Support

I would love to get some support for windows.
What's still missing:

  • Process signal handling
  • Terminal support
  • Process spawning support

Daemon is running, but not responding to client

Today I encountered a situation in which the daemon was still running, but it didn't respond to any client connections.
There was nothing in the daemon.log and I had to kill it with a SIGINT.

This needs further debugging, but it's the only time I encountered it.

Theory:
Two clients connected at the exact same time, which caused unexpected behaviour?

Machine friendly output

I want to write some tooling for pueue (specifically integration with bitbar) but currently the output of all commands is only human friendly.

It'd be nice if all commands (but mainly status) had a JSON output flag.

Inconsistency in passing a key

Hi,
I've noticed that some of the subcommands require the key to be passed as an argument, while others require a -k/--key option to specify a key. I suppose this is because some commands have a meaning even without a key?
Do you think it is a good idea to make them more uniform? I personally find this way to be slightly confusing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.