<commit_before>package queue

import (
	"context"

	"cloud.google.com/go/pubsub"
	"code.cloudfoundry.org/lager"
)

//go:generate counterfeiter . Topic

type Topic interface {
	Publish(context.Context, *pubsub.Message) ([]string, error)
}

type pubSubEnqueuer struct {
	logger lager.Logger
	topic  Topic
}

func NewPubSubEnqueuer(logger lager.Logger, topic Topic) Enqueuer {
	return &pubSubEnqueuer{
		logger: logger,
		topic:  topic,
	}
}

func (p *pubSubEnqueuer) Enqueue(task Task) error {
	message := &pubsub.Message{
		Attributes: map[string]string{
			"id":   task.ID(),
			"type": task.Type(),
		},
		Data: []byte(task.Payload()),
	}

	_, err := p.topic.Publish(context.TODO(), message)
	if err != nil {
		return err
	}

	return nil
}<commit_msg>Add logging to pub sub enqueuer<commit_after>package queue

import (
	"context"

	"cloud.google.com/go/pubsub"
	"code.cloudfoundry.org/lager"
)

//go:generate counterfeiter . Topic

type Topic interface {
	Publish(context.Context, *pubsub.Message) ([]string, error)
}

type pubSubEnqueuer struct {
	logger lager.Logger
	topic  Topic
}

func NewPubSubEnqueuer(logger lager.Logger, topic Topic) Enqueuer {
	return &pubSubEnqueuer{
		logger: logger,
		topic:  topic,
	}
}

func (p *pubSubEnqueuer) Enqueue(task Task) error {
	message := &pubsub.Message{
		Attributes: map[string]string{
			"id":   task.ID(),
			"type": task.Type(),
		},
		Data: []byte(task.Payload()),
	}

	_, err := p.topic.Publish(context.TODO(), message)
	if err != nil {
		p.logger.Error("failed-to-publish", err)
		return err
	}

	p.logger.Info("successfully-published", lager.Data{
		"id":   task.ID(),
		"type": task.Type(),
	})

	return nil
}
{'fraction_non_alphanumeric': 0.14997000599880023, 'fraction_numerical': 0.0, 'mean_word_length': 4.085365853658536, 'pattern_counts': {'":': 6, '<': 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': '4216160', 'n_tokens_mistral': 660, 'n_tokens_neox': 626, 'n_words': 135}