executor

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2025 License: GPL-2.0 Imports: 1 Imported by: 0

README ΒΆ

βš™οΈ Executor

Executor is a high-performance command-line utility written in Go, designed to orchestrate and execute parallel processes efficiently. It supports batching, offset/limit control, parallel execution, and templated command execution.

Ideal for automating batch jobs, parallel task runners, or any scenario where you need structured control over concurrent executions.


✨ Features

  • πŸ” Parallel execution of custom shell commands
  • πŸ“¦ Batch processing with offset and limit control
  • 🧠 Templated commands using Go templates
  • πŸ•’ Timeout support per command
  • πŸ“‚ Per-process logging with optional stderr output
  • πŸ› οΈ Fully configurable working directory, shell, and logging behavior

πŸ“Œ Example Usage

πŸ§ͺ Basic Run
executor --limit 10000 --batch-size 1000 --processors 5 --log-stderr

This runs 10 batches (1000 items per batch) in parallel using 5 workers.


πŸ“œ Custom Command Template
executor -l 5000 -c 'curl http://localhost/data?start={{ .offset }}&end={{ sum .offset .batchSize }}'

Command templates support Go template syntax and include:

  • .offset β†’ current offset
  • .batchSize β†’ batch size
  • .limit β†’ total limit
  • sum β†’ built-in function for arithmetic

You can see more builtin functions at Template section.


πŸ’¬ Logging to stderr
executor --log-stderr --verbose

The default behavior is to log into files with name exec-<begin>-<end>.log Using --log-stderr flag you can see logs of each processor in stderr

Please note that default logging system is pretty chatty if you have seen a bug


πŸ”§ Flags

  --batch-size int            Batch size for processing (default 1000)
  -c, --command string        Command to execute (Go template with vars: offset, batchSize, limit) 
                              (default "echo {{ .offset | sum .batchSize }}={{ .limit }}")
  --stdin string              Stdin passed to process (Go template with vars: offset, batchSize, limit) 
                              (default "")
  -l, --limit int             Total number of items to process
  -o, --offset int            Starting offset
  -p, --processors int        Number of parallel executions (default 10)
  --timeout duration          Timeout per command (default 24h0m0s)
  --shell string              Shell to execute commands with (default "/bin/sh")
  --shell-args strings        Shell arguments (default: [-c])
  -w, --working-directory     Working directory (default: current directory)
  --log-dir string            Log file directory (default: current directory)
  --log-stderr                Stream logs to stderr instead of files
  -v, --verbose               Enables verbose logging
  -h, --help                  Display help

πŸ›  Installation

πŸ“¦ Using go install
go install github.com/FMotalleb/executor@latest

Make sure $GOPATH/bin is in your $PATH.

πŸ§ͺ Build from source
git clone https://github.com/FMotalleb/executor.git
cd executor
go build -o executor
./executor --help

πŸ“ Example Log Output

When not using --log-stderr, logs are written per execution in the specified log directory:

/home/you/executor/logs/
  β”œβ”€β”€ run_001.log
  β”œβ”€β”€ run_002.log
  └── ...

🧩 Template Functions

The --command flag uses Go's text/template engine, with the following built-in helpers:

Function Description
env "KEY" Gets environment variable KEY
b64enc Base64-encodes a string
b64dec Decodes a base64-encoded string
sum a b Returns a + b
toUpper Converts string to UPPERCASE
toLower Converts string to lowercase
trim Trims whitespace from both ends
join list sep Joins a list with separator
replace a b Replaces all a with b in a string
hasPrefix Checks if string has given prefix
hasSuffix Checks if string has given suffix
contains Checks if string contains substring
toJSON Encodes input to JSON
fromJSON Decodes JSON string to map
itoa Converts integer to string
atoi Converts string to integer
toInt Same as atoi, converts to int
atob Alias for base64 decode

Documentation ΒΆ

Overview ΒΆ

Copyright Β© 2025 Motalleb Fallahnezhad

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Directories ΒΆ

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL