<commit_before>package blocks

import (
	"encoding/json"
	"github.com/bitly/go-nsq"
	"log"
)

func ToNSQ(b *Block) {

	type toNSQRule struct {
		NsqdHTTPAddrs string
		Topic         string
	}

	var rule *toNSQRule
	var w *nsq.Writer

	// TODO check the endpoint for happiness
	for {
		select {
		case msg := <-b.AddChan:
			updateOutChans(msg, b)
		case <-b.QuitChan:
			quit(b)
			return
		case msg := <-b.InChan:
			if rule == nil {
				break
			}
			blob, err := json.Marshal(msg)
			if err != nil {
				log.Println("failed to marshal JSON")
			}
			frameType, data, err := w.Publish(rule.Topic, blob)
			if err != nil {
				log.Fatalf("frametype %d data %s error %s", frameType, string(data), err.Error())
			}
		case msg := <-b.Routes["set_rule"]:
			if rule == nil {
				rule = &toNSQRule{}
			}
			unmarshal(msg, rule)
			w = nsq.NewWriter(rule.NsqdHTTPAddrs)
		case msg := <-b.Routes["get_rule"]:<commit_msg>no fatal error in NSQ, allow for lazy re-connect<commit_after>package blocks

import (
	"encoding/json"
	"github.com/bitly/go-nsq"
	"log"
)

func ToNSQ(b *Block) {

	type toNSQRule struct {
		NsqdHTTPAddrs string
		Topic         string
	}

	var rule *toNSQRule
	var w *nsq.Writer

	// TODO check the endpoint for happiness
	for {
		select {
		case msg := <-b.AddChan:
			updateOutChans(msg, b)
		case <-b.QuitChan:
			quit(b)
			return
		case msg := <-b.InChan:
			if rule == nil {
				break
			}
			blob, err := json.Marshal(msg)
			if err != nil {
				log.Println("failed to marshal JSON")
			}
			frameType, data, err := w.Publish(rule.Topic, blob)

			if err != nil {
				log.Println("frametype %d data %s error %s", frameType, string(data), err.Error())
			}

		case msg := <-b.Routes["set_rule"]:
			if rule == nil {
				rule = &toNSQRule{}
			}
			unmarshal(msg, rule)
			w = nsq.NewWriter(rule.NsqdHTTPAddrs)
		case msg := <-b.Routes["get_rule"]:
{'fraction_non_alphanumeric': 0.1443850267379679, 'fraction_numerical': 0.0, 'mean_word_length': 2.8028455284552845, 'pattern_counts': {'":': 0, '<': 13, '<?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': '1822766', 'n_tokens_mistral': 854, 'n_tokens_neox': 724, 'n_words': 183}