<commit_before>package hm

import (
	"errors"
	"fmt"
	"os"
	"time"

	"github.com/cloudfoundry/hm9000/helpers/logger"
	"github.com/cloudfoundry/storeadapter"
)

func Daemonize(
	component string,
	callback func() error,
	period time.Duration,
	timeout time.Duration,
	logger logger.Logger,
	adapter storeadapter.StoreAdapter,
) error {
	logger.Info("Acquiring lock for " + component)

	lock := storeadapter.StoreNode{
		Key: "/hm/locks/" + component,
		TTL: 10,
	}

	status, releaseLockChannel, err := adapter.MaintainNode(lock)
	if err != nil {
		logger.Info(fmt.Sprintf("Failed to acquire lock: %s", err))
		return err
	}

	lockAcquired := make(chan bool)

	go func() {
		l := lockAcquired
		for {
			if <-status {
				if l != nil {
					close(l)
					l = nil
				}
			} else {
				logger.Error("Lost the lock", errors.New("Lock the lock"))
				os.Exit(197)
			}
		}
	}()

	<-lockAcquired

	logger.Info("Acquired lock for " + component)

	logger.Info(fmt.Sprintf("Running Daemon every %d seconds with a timeout of %d", int(period.Seconds()), int(timeout.Seconds())))

	for {
		afterChan := time.After(period)<commit_msg>Losing the lock is not an error (part deux)<commit_after>package hm

import (
	"errors"
	"fmt"
	"os"
	"time"

	"github.com/cloudfoundry/hm9000/helpers/logger"
	"github.com/cloudfoundry/storeadapter"
)

func Daemonize(
	component string,
	callback func() error,
	period time.Duration,
	timeout time.Duration,
	logger logger.Logger,
	adapter storeadapter.StoreAdapter,
) error {
	logger.Info("Acquiring lock for " + component)

	lock := storeadapter.StoreNode{
		Key: "/hm/locks/" + component,
		TTL: 10,
	}

	status, releaseLockChannel, err := adapter.MaintainNode(lock)
	if err != nil {
		logger.Info(fmt.Sprintf("Failed to acquire lock: %s", err))
		return err
	}

	lockAcquired := make(chan bool)

	go func() {
		l := lockAcquired
		for {
			if <-status {
				if l != nil {
					close(l)
					l = nil
				}
			} else {
				logger.Info("Lost the lock")
				os.Exit(197)
			}
		}
	}()

	<-lockAcquired

	logger.Info("Acquired lock for " + component)

	logger.Info(fmt.Sprintf("Running Daemon every %d seconds with a timeout of %d", int(period.Seconds()), int(timeout.Seconds())))

	for {
		afterChan := time.After(period)
{'fraction_non_alphanumeric': 0.1409455842997324, 'fraction_numerical': 0.008028545941123996, 'mean_word_length': 3.5682281059063135, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2699516', 'n_tokens_mistral': 902, 'n_tokens_neox': 785, 'n_words': 194}