runner

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2014 License: MIT Imports: 4 Imported by: 2

README

queued-command-runner

Build Status GoDoc

Documentation lives here

Documentation

Overview

Package runner runs distinct commands in parallel goroutines while queueing indistinct commands so they're never run twice at the same time (but all get run eventually).

Simply send your command to runner and let it do the rest!

Example usage:

  package main

  import "github.com/modcloth/queued-command-runner"

  import (
  	"fmt"
  	"os"
  	"os/exec"
  )

  func main() {
  	fmt.Println("Running a command now.")

  	pwd := os.Getenv("PWD")

	ls := exec.Command("ls", "-la", pwd)
	ls.Stdout = os.Stdout
	ls.Stderr = os.Stderr
	cmd := &runner.Command{
		Cmd: ls,
	}

	runner.Run(cmd)

  	WaitOnRunner:
  	for {
  		select {
  		case <-runner.Done:
  			break WaitOnRunner
		case err := <-runner.Errors:
			fmt.Printf("Uh oh, got an error: %q\n", err)
  		}
  	}

  	os.Exit(0)
  }

Index

Constants

This section is empty.

Variables

View Source
var Done = make(chan bool)

Done is qcr's exit channel - if you use qcr, you MUST wait on Done to ensure your commands get run. This can be accomplished by including the following at the bottom of main():

<-runner.Done
View Source
var Errors = make(chan *QCRError)

Error is the channel that qcr will use to report any errors that occur.

View Source
var Logger *logrus.Logger

Logger is the logger used by the runner package. It is initialized in the init() function so it may be overwritten any time after that.

Functions

func Run

func Run(cmd *Command)

Run runs your command.

Types

type Command added in v0.2.0

type Command struct {
	Key string
	Cmd *exec.Cmd
}

Command is a small wrapper for *exec.Cmd so that a custom key may be specified. If no key is specified (i.e. Key == ""), key is defaulted to the following:

key = strings.Join(cmd.Cmd.Args, " ")

type QCRError

type QCRError struct {
	CommandStr string
	Key        string
	// contains filtered or unexported fields
}

QCRError is a custom error type that includes CommandStr, the command args of the command that failed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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