Exemple #1
0
// connect gives you a client connected to a queue that shouldn't be used; use
// the client just for calling non-queue-specific methods such as getting
// server status or shutting it down etc.
func connect(wait time.Duration) *jobqueue.Client {
	jq, jqerr := jobqueue.Connect("localhost:"+config.ManagerPort, "test_queue", wait)
	if jqerr == nil {
		return jq
	}
	return nil
}
Exemple #2
0
		// open file or set up to read from STDIN
		var reader io.Reader
		if cmdFile == "-" {
			reader = os.Stdin
		} else {
			reader, err = os.Open(cmdFile)
			if err != nil {
				die("could not open file '%s': %s", cmdFile, err)
			}
			defer reader.(*os.File).Close()
		}

		// we'll default to pwd if the manager is on the same host as us, /tmp
		// otherwise
		jq, err := jobqueue.Connect(addr, "cmds", timeout)
		if err != nil {
			die("%s", err)
		}
		sstats, err := jq.ServerStats()
		if err != nil {
			die("even though I was able to connect to the manager, it failed to tell me its location")
		}
		var pwd string
		var pwdWarning int
		if jobqueue.CurrentIP()+":"+config.ManagerPort == sstats.ServerInfo.Addr {
			pwd, err = os.Getwd()
			if err != nil {
				die("%s", err)
			}
		} else {
Exemple #3
0
the runner to kill itself if the cmd it is running takes longer than max_time to
complete.`,
	Run: func(cmd *cobra.Command, args []string) {
		if queuename == "" {
			die("--queue is required")
		}

		// the server receive timeout must be greater than the time we'll wait
		// to Reserve()
		if timeoutint < (reserveint + 5) {
			timeoutint = reserveint + 5
		}
		timeout := time.Duration(timeoutint) * time.Second
		rtimeout := time.Duration(reserveint) * time.Second

		jq, err := jobqueue.Connect(rserver, queuename, timeout)
		if err != nil {
			die("%s", err)
		}
		defer jq.Disconnect()

		// we'll stop the below loop before using up too much time
		var endTime time.Time
		if maxtime > 0 {
			endTime = time.Now().Add(time.Duration(maxtime) * time.Minute)
		} else {
			endTime = time.Now().AddDate(1, 0, 0) // default to allowing us a year to run
		}

		// loop, reserving and running commands from the queue, until there
		// aren't any more commands in the queue