<commit_before>package mq_test

import (
	"fmt"
	"github.com/manveru/go.iron/mq"
)

var p = fmt.Println

func Example1PushingMessagesToTheQueue() {
	// use the test_queue to push/get messages
	q := mq.New("test_queue")

	q.PushString("Hello, World!")

	// You can also pass multiple messages in a single call.
	q.PushStrings("Message 1", "Message 2")

	// To control parameters like timeout and delay, construct your own message.
	q.PushMessage(&mq.Message{Timeout: 60, Delay: 0, Body: "Hi there"})

	// And finally, all that can be done in bulk as well.
	q.PushMessages(
		&mq.Message{Timeout: 60, Delay: 0, Body: "The first"},
		&mq.Message{Timeout: 60, Delay: 1, Body: "The second"},
		&mq.Message{Timeout: 60, Delay: 2, Body: "The third"},
		&mq.Message{Timeout: 60, Delay: 3, Body: "The fifth"},
	)

	p("all pushed")

	// Output:
	// all pushed
}

func Example2GettingMessagesOffTheQueue() {
	q := mq.New("test_queue")

	// get a single message
	msg, err := q.Get()
	p(err)
	p(msg.Body)

	// get 5 messages
	msgs, err := q.GetN(5)
	p(err)
	p(len(msgs))

	for _, m := range append(msgs, msg) {
		m.Delete()
	}

	// Output:
	// <nil>
	// Hello, World!
	// <nil>
	// 5
}

func Example3DeleteMessagesFromTheQueue() {
	q := mq.New("test_queue")
	msg, err := q.Get()
	p(err)
	msg.Delete()

	// Output:
	// <nil>
}

func Example4ClearQueue() {
	q := mq.New("test_queue")

	for {
		msgs, err := q.GetN(100)
		if err != nil {
			p(err)
			break
		}
		if len(msgs) <= 0 {
			break
		}

		for _, msg := range msgs {
			msg.Delete()
		}
	}

	info, err := q.Info()

	p(err)
	p("Name:", info.Name)
	p("Size:", info.Size)

	// Output:
	// <nil>
	// Name: test_queue
	// Size: 0
}<commit_msg>add mq clean test<commit_after>package mq_test

import (
	"fmt"
	"github.com/manveru/go.iron/mq"
)

var p = fmt.Println

func Example1PushingMessagesToTheQueue() {
	// use the test_queue to push/get messages
	q := mq.New("test_queue")

	q.PushString("Hello, World!")

	// You can also pass multiple messages in a single call.
	q.PushStrings("Message 1", "Message 2")

	// To control parameters like timeout and delay, construct your own message.
	q.PushMessage(&mq.Message{Timeout: 60, Delay: 0, Body: "Hi there"})

	// And finally, all that can be done in bulk as well.
	q.PushMessages(
		&mq.Message{Timeout: 60, Delay: 0, Body: "The first"},
		&mq.Message{Timeout: 60, Delay: 1, Body: "The second"},
		&mq.Message{Timeout: 60, Delay: 2, Body: "The third"},
		&mq.Message{Timeout: 60, Delay: 3, Body: "The fifth"},
	)

	p("all pushed")

	// Output:
	// all pushed
}

func Example2GettingMessagesOffTheQueue() {
	q := mq.New("test_queue")

	// get a single message
	msg, err := q.Get()
	p(err)
	p(msg.Body)

	// get 5 messages
	msgs, err := q.GetN(5)
	p(err)
	p(len(msgs))

	for _, m := range append(msgs, msg) {
		m.Delete()
	}

	// Output:
	// <nil>
	// Hello, World!
	// <nil>
	// 5
}

func Example3DeleteMessagesFromTheQueue() {
	q := mq.New("test_queue")
	msg, err := q.Get()
	p(err)
	msg.Delete()

	// Output:
	// <nil>
}

func Example4ClearQueue() {
	q := mq.New("test_queue")

	info, err := q.Info()

	p(err)
	p("Name:", info.Name)
	p("Size:", info.Size)

	err = q.Clear()
	p(err)

	info, err = q.Info()

	p(err)
	p("Name:", info.Name)
	p("Size:", info.Size)

	// Output:
	// <nil>
	// Name: test_queue
	// Size: 0
	// <nil>
	// Name: test_queue
	// Size: 0
	// <nil>
	// Name: test_queue
	// Size: 0
}
{'fraction_non_alphanumeric': 0.18189858490566038, 'fraction_numerical': 0.01650943396226415, 'mean_word_length': 3.1327649208282584, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7354172', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1357, 'n_words': 360}