コード例 #1
0
ファイル: mq.go プロジェクト: romand/ironcli
func (r *RmCmd) Run() {
	var queues []mq.Queue

	if isPipedIn() {
		scanner := bufio.NewScanner(os.Stdin)
		for scanner.Scan() {
			name := scanner.Text()
			queues = append(queues, mq.ConfigNew(name, &r.settings))
		}
		if err := scanner.Err(); err != nil {
			fmt.Fprintln(os.Stderr, err)
		}
	} else {
		queues = append(queues, mq.ConfigNew(r.queue_name, &r.settings))
	}

	for _, q := range queues {
		err := q.Delete()
		if err != nil {
			fmt.Println(red("Error deleting queue ", q.Name, ": ", err))
		} else {
			fmt.Println(green(LINES, q.Name, " has been sucessfully deleted."))
		}
	}
}
コード例 #2
0
ファイル: mq.go プロジェクト: romand/ironcli
func (p *PeekCmd) Run() {
	q := mq.ConfigNew(p.queue_name, &p.settings)

	msgs, err := q.PeekN(*p.n)
	if err != nil {
		fmt.Fprintln(os.Stderr, red(err))
		return
	}

	if len(msgs) < 1 {
		fmt.Fprintln(os.Stderr, red("Queue is empty."))
		return
	}

	if !isPipedOut() {
		plural := ""
		if *p.n > 1 {
			plural = "s"
		}
		fmt.Println(green(LINES, "Message", plural, " successfully peeked"))
		fmt.Println()
		fmt.Println("-------- ID ------ | Body")
	}
	printMessages(msgs)
}
コード例 #3
0
ファイル: mq.go プロジェクト: romand/ironcli
func (p *PopCmd) Run() {
	q := mq.ConfigNew(p.queue_name, &p.settings)

	messages, err := q.PopN(*p.n)
	if err != nil {
		fmt.Fprintln(os.Stderr, red(err))
	}

	// If anything here fails, we still want to print out what was deleted before exiting
	if p.file != nil {
		b, err := json.Marshal(messages)
		if err != nil {
			fmt.Fprintln(os.Stderr, red(err))
			printMessages(messages)
		}
		_, err = p.file.Write(b)
		if err != nil {
			fmt.Fprintln(os.Stderr, red(err))
			printMessages(messages)
		}
	}

	if isPipedOut() {
		printMessages(messages)
	} else {
		plural := ""
		if *p.n > 1 {
			plural = "s"
		}
		fmt.Println(green(LINES, "Message", plural, " successfully popped off ", q.Name))
		fmt.Println()
		fmt.Println("-------- ID ------ | Body")
		printMessages(messages)
	}
}
コード例 #4
0
ファイル: mq.go プロジェクト: romand/ironcli
func (i *InfoCmd) Run() {
	q := mq.ConfigNew(i.queue_name, &i.settings)
	info, err := q.Info()
	if err != nil {
		fmt.Fprintln(os.Stderr, red(err))
		return
	}
	fmt.Printf("%sName: %s\n", BLANKS, info.Name)
	fmt.Printf("%sCurrent Size: %d\n", BLANKS, info.Size)
	fmt.Printf("%sTotal messages: %d\n", BLANKS, info.TotalMessages)
	fmt.Printf("%sMessage expiration: %d\n", BLANKS, info.MessageExpiration)
	fmt.Printf("%sMessage timeout: %d\n", BLANKS, info.MessageTimeout)
	if info.Push != nil {
		fmt.Printf("%sType: %s\n", BLANKS, *info.Type)
		fmt.Printf("%sSubscribers: %d\n", BLANKS, len(info.Push.Subscribers))
		fmt.Printf("%sRetries: %d\n", BLANKS, info.Push.Retries)
		fmt.Printf("%sRetries delay: %d\n", BLANKS, info.Push.RetriesDelay)
		if *i.subscriberList {
			fmt.Printf("%sSubscriber list\n", LINES)
			printSubscribers(info)
			fmt.Println()
		}
	}
	printQueueHudURL(BLANKS, q)
}
コード例 #5
0
ファイル: mq.go プロジェクト: romand/ironcli
func (c *ClearCmd) Run() {
	q := mq.ConfigNew(c.queue_name, &c.settings)
	if err := q.Clear(); err != nil {
		fmt.Println(red("Error clearing queue:", err))
		return
	}
	fmt.Fprintln(os.Stderr, green(LINES, "Queue ", q.Name, " has been successfully cleared"))
}
コード例 #6
0
ファイル: main.go プロジェクト: nicksardo/enqueuer
func main() {
	settings := &config.Settings{
		Token:     "x",
		ProjectId: "y",
		Host:      "abc.iron.io",
	}
	q := mq.ConfigNew("sampleQueue", settings)

	FlatLoad(&q, 1000)
}
コード例 #7
0
ファイル: mq.go プロジェクト: romand/ironcli
// This doesn't work with reserved messages
// TODO: add --reserved flag to work with reserved messages
// TODO: Make the message not found error more descriptive.
func (d *DeleteCmd) Run() {
	q := mq.ConfigNew(d.queue_name, &d.settings)

	err := q.DeleteMessages(d.ids)
	if err != nil {
		fmt.Println(red(BLANKS, err))
		return
	}

	plural := ""
	if len(d.ids) > 1 {
		plural = "s"
	}
	fmt.Println(green(BLANKS, "Done deleting message", plural))

}
コード例 #8
0
ファイル: mq.go プロジェクト: romand/ironcli
func (c *CreateCmd) Run() {
	fmt.Printf("%sCreating queue \"%s\"\n", BLANKS, c.queue_name)
	q := mq.ConfigNew(c.queue_name, &c.settings)
	_, err := q.PushStrings("")
	if err != nil {
		fmt.Fprintln(os.Stderr, red(BLANKS, "create error: ", err))
		return
	}
	err = q.Clear()
	if err != nil {
		fmt.Fprintln(os.Stderr, red(BLANKS, "create error: ", err))
	}

	fmt.Println(green(LINES, "Queue ", q.Name, " has been successfully created."))
	printQueueHudURL(BLANKS, q)
}
コード例 #9
0
ファイル: main.go プロジェクト: nicksardo/triggers
func watchTriggers(a QueueWorkerAlert, wg *sync.WaitGroup, stop chan struct{}) {
	defer wg.Done()

	// Determine trigger check interval
	interval := defaultInterval
	if a.Interval != nil && *a.Interval >= 1 {
		interval = time.Duration(*a.Interval) * time.Second
	}

	// Queue Settings
	queueEnv, exists := c.getSettings("mq", a.QueueEnv)
	if !exists {
		fmt.Printf("Environment %q is not defined for queue %q\n", a.QueueEnv, a.QueueName)
		return
	}
	q := mq.ConfigNew(a.QueueName, queueEnv)

	// Worker Settings
	workerEnv, exists := c.getSettings("worker", a.WorkerEnv)
	if !exists {
		fmt.Printf("Environment %q is not defined for queue %q\n", a.QueueEnv, a.QueueName)
		return
	}

	knowPrevious := a.needPreviousSize()

Loop:
	for {
		checkTriggers(a, q, workerEnv, a.WorkerName, knowPrevious)

		// Decide to stop looping
		select {
		case <-stop:
			break Loop
		default:
		}

		time.Sleep(interval)
	}
}
コード例 #10
0
ファイル: mq.go プロジェクト: romand/ironcli
func (p *PushCmd) Run() {
	q := mq.ConfigNew(p.queue_name, &p.settings)

	ids, err := q.PushStrings(p.messages...)
	if err != nil {
		fmt.Fprintln(os.Stderr, red(err))
	}

	if isPipedOut() {
		for _, id := range ids {
			fmt.Println(id)
		}
	} else {
		fmt.Println(green(LINES, "Message succesfully pushed!"))
		fmt.Printf("%sMessage IDs:\n", BLANKS)
		fmt.Printf("%s", BLANKS)
		for _, id := range ids {
			fmt.Printf("%s ", id)
		}
		fmt.Println()
	}
}
コード例 #11
0
ファイル: mq.go プロジェクト: romand/ironcli
func (r *ReserveCmd) Run() {
	q := mq.ConfigNew(r.queue_name, &r.settings)
	messages, err := q.GetNWithTimeout(*r.n, *r.timeout)
	if err != nil {
		fmt.Fprintln(os.Stderr, red(err))
	}

	// If anything here fails, we still want to print out what was reserved before exiting
	if r.file != nil {
		b, err := json.Marshal(messages)
		if err != nil {
			fmt.Fprintln(os.Stderr, red(err))
			printReservedMessages(messages)
			return
		}
		_, err = r.file.Write(b)
		if err != nil {
			fmt.Fprintln(os.Stderr, red(err))
			printReservedMessages(messages)
			return
		}
	}

	if len(messages) < 1 {
		fmt.Fprintln(os.Stderr, red("Queue is empty"))
		return
	}

	if isPipedOut() {
		printReservedMessages(messages)
	} else {
		fmt.Println(green(LINES, "Messages successfully reserved"))
		fmt.Println("--------- ID ------|------- Reservation ID -------- | Body")
		printReservedMessages(messages)
	}
}
コード例 #12
0
ファイル: main.go プロジェクト: nicksardo/dequeuer
func main() {
	start := time.Now()

	// Parse config json and validate
	worker.ParseFlags()
	c := DefaultConfig()
	worker.ConfigFromJSON(c)
	if err := c.Valid(); err != nil {
		log.Fatal(err)
	}

	// Copy config, obfuscate token, and print for record
	copy := *c
	copy.Env.Token = obfuscate(copy.Env.Token)
	j, err := json.MarshalIndent(copy, "", "    ")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(j))

	// Retrieve queue info
	s := config.ManualConfig("iron_mq", &c.Env)
	t := time.Now()
	q := mq.ConfigNew(c.QueueName, &s)
	info, err := q.Info()
	if err != nil {
		log.Fatal("Could not access queue info", err)
	}
	fmt.Printf("Queue has %d messages. (request took %v)\n", info.Size, time.Since(t))

	// Loop for multiple iterations of dequeuing & processing messages
	emptyResultCount := 0
	totalProcessedCount := 0
batchLoop:
	for x := 0; c.MaxIterations == nil || x < *c.MaxIterations; x++ {
		// Determine if we have time for another set of processing
		if time.Since(start) > c.MaxDuration {
			break
		}

		// If configured, sleep between iterations
		if x != 0 {
			fmt.Println("Sleeping", c.IterationSleep)
			time.Sleep(c.IterationSleep)
		}

		// Create a timeout that can accommodate the duration of the entire batch
		timeout := float64(c.BatchSize) * c.MsgDuration.Seconds() * 1.1 // give it an extra 10% time for safety

		// Reserve messages with given batch size, timeout, and longpoll time
		t = time.Now()
		msgs, err := q.LongPoll(c.BatchSize, int(timeout), c.DequeueWait, false)
		if err != nil {
			// Ideally, continue the loop and try again later. After a certain amount of time, do panic/Fatal
			log.Fatal(err)
		}
		fmt.Printf("Iteration %d: Requested %d, got %d (request took %v with a max wait of %ds)\n", x, c.BatchSize, len(msgs), time.Since(t), c.DequeueWait)

		// Handle case of zero messages
		if len(msgs) == 0 && c.MaxEmptyResults != nil {
			emptyResultCount++
			if emptyResultCount >= *c.MaxEmptyResults {
				fmt.Println("Queue is empty - breaking work loop")
				break
			}
		} else {
			// Reset count if queue isn't empty
			emptyResultCount = 0
		}

		// Process each message
		for i, msg := range msgs {
			// Determine if we have time to process another message
			if time.Since(start) > c.MaxDuration+c.MsgDuration {
				fmt.Println("Not enough time to process message - breaking work loop")
				break batchLoop
			}

			// Simulate Message Processing
			time.Sleep(c.MsgDuration)
			fmt.Printf(" %d: %q\n", i, msg.Body)

			// Example case for error processing
			var processingError error
			if processingError != nil {
				// Move error to error queue
				// errorQueue.Push(msg)
			}

			totalProcessedCount++

			// Delete processed message from queue
			err = msg.Delete()
			if err != nil {
				fmt.Println("Could not delete msg:", msg.Body, err)
			}
		}
	}

	fmt.Printf("Worker ending after %s and processing %d messages", time.Since(start), totalProcessedCount)
}