<commit_before>package queue

import (
	"encoding/json"
	"github.com/streadway/amqp"
)

// Connection wraps an AMQP connection
type Connection struct {
	*amqp.Connection
}

// NewConnection returns new AMQP connection
func NewConnection(url string) (*Connection, error) {
	connection, err := amqp.Dial(url)

	if err != nil {
		return nil, err
	}

	return &Connection{Connection: connection}, nil
}

// NewChannel initialises an AMQP channel
func (conn *Connection) NewChannel() (*Channel, error) {
	ch, err := conn.Channel()
	if err != nil {
		return nil, err
	}

	err = ch.Qos(
		1,     // prefetch count
		0,     // prefetch size
		false, // global
	)
	if err != nil {
		return nil, err
	}

	return &Channel{
		Channel: ch,
	}, nil
}

// Channel wraps an AMQP channel
type Channel struct {
	*amqp.Channel
}

// Close closes a Channel
func (c *Channel) Close() error {
	err := c.Close()
	if err != nil {
		return err
	}

	return nil
}

// Queue wraps an channel/queue for tasks
type Queue struct {
	Channel *Channel
	*amqp.Queue
}

// String returns the name of the queue
func (q *Queue) String() string {
	return q.Name
}

// NewQueue creates a named queue on a given chennel
func (c *Channel) NewQueue(name string) (*Queue, error) {
	args := amqp.Table{
		"x-max-priority": 9,
	}

	q, err := c.Channel.QueueDeclare(
		name,  // name
		true,  // durable
		false, // delete when unused
		false, // exclusive<commit_msg>Expire messages after 24 hours.<commit_after>package queue

import (
	"encoding/json"
	"github.com/streadway/amqp"
)

// Connection wraps an AMQP connection
type Connection struct {
	*amqp.Connection
}

// NewConnection returns new AMQP connection
func NewConnection(url string) (*Connection, error) {
	connection, err := amqp.Dial(url)

	if err != nil {
		return nil, err
	}

	return &Connection{Connection: connection}, nil
}

// NewChannel initialises an AMQP channel
func (conn *Connection) NewChannel() (*Channel, error) {
	ch, err := conn.Channel()
	if err != nil {
		return nil, err
	}

	err = ch.Qos(
		1,     // prefetch count
		0,     // prefetch size
		false, // global
	)
	if err != nil {
		return nil, err
	}

	return &Channel{
		Channel: ch,
	}, nil
}

// Channel wraps an AMQP channel
type Channel struct {
	*amqp.Channel
}

// Close closes a Channel
func (c *Channel) Close() error {
	err := c.Close()
	if err != nil {
		return err
	}

	return nil
}

// Queue wraps an channel/queue for tasks
type Queue struct {
	Channel *Channel
	*amqp.Queue
}

// String returns the name of the queue
func (q *Queue) String() string {
	return q.Name
}

// NewQueue creates a named queue on a given chennel
func (c *Channel) NewQueue(name string) (*Queue, error) {
	args := amqp.Table{
		"x-max-priority": 9,                   // Enable all 9 priorities
		"x-message-ttl":  1000 * 60 * 60 * 24, // Expire messages after 24 hours
	}

	q, err := c.Channel.QueueDeclare(
		name,  // name
		true,  // durable
		false, // delete when unused
		false, // exclusive
{'fraction_non_alphanumeric': 0.1229012760241773, 'fraction_numerical': 0.007051712558764272, 'mean_word_length': 3.047554347826087, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, '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': '2173060', 'n_tokens_mistral': 1068, 'n_tokens_neox': 995, 'n_words': 345}