<commit_before>package main

import (
	"path"

	"github.com/coreos/muffins/machine"
	"github.com/coreos/go-etcd/etcd"
	"github.com/coreos/go-systemd/dbus"
)

const keyPrefix = "/core-init/system/"

func init() {
}

/*
func startUnit() {
	script := []string{"/bin/sh", "-c",
		"while true; do echo goodbye world; sleep 1; done"}

	jobid, err := systemd.StartTransientUnit("hello.service",
		"replace",
		dbus.PropExecStart(script, false))
	fmt.Println(jobid, err)
}
*/

func main() {
	etcdC := etcd.NewClient(nil)
	mach := machine.NewMachine("")
	prefix := path.Join(keyPrefix, mach.BootId)

	systemd := dbus.New()
	units, err := systemd.ListUnits()
	if err != nil {
		panic(err)
	}

	for _, u := range(units) {
		if u.ActiveState == "active" {
			println(u.Name, u.ActiveState)
			key := path.Join(prefix, u.Name)
			etcdC.Set(key, "active", 0)
		}
	}
}
<commit_msg>feat(muffins): write all of the keys on an interval<commit_after>package main

import (
	"path"
	"time"

	"github.com/coreos/muffins/machine"
	"github.com/coreos/go-etcd/etcd"
	"github.com/coreos/go-systemd/dbus"
)

const keyPrefix = "/core-init/system/"
// TODO: Make this a variable
const ttl = 10

type Init struct {
	Etcd *etcd.Client
	Systemd *dbus.Conn
	Machine *machine.Machine
}

func init() {
}

/*
func startUnit() {
	script := []string{"/bin/sh", "-c",
		"while true; do echo goodbye world; sleep 1; done"}

	jobid, err := i.Systemd.StartTransientUnit("hello.service",
		"replace",
		dbus.PropExecStart(script, false))
	fmt.Println(jobid, err)
}
*/

// heartbeat ensures that all of the units 
func (i *Init) StartHeartbeat() {
	// TODO: Use the new directory TTL in the v2 API instead of
	// heartbeating all of the units
	interval := ttl / 2.0
	
	c := time.Tick(time.Duration(interval) * time.Second)
	for now := range c {
		println(now.String())
		go i.SetAllUnits()
	}
}

func (i *Init) SetAllUnits() {
	units, err := i.Systemd.ListUnits()
	if err != nil {
		panic(err)
	}

	prefix := path.Join(keyPrefix, i.Machine.BootId)
	for _, u := range(units) {
		if u.ActiveState == "active" {
			println(u.Name, u.ActiveState)
			key := path.Join(prefix, u.Name)
			i.Etcd.Set(key, "active", 0)
		}
	}
}

func main() {
	etcdC := etcd.NewClient(nil)
	mach := machine.NewMachine("")
	systemd := dbus.New()

	init := Init{etcdC, systemd, mach}

	init.SetAllUnits()
	init.StartHeartbeat()
}

{'fraction_non_alphanumeric': 0.1694915254237288, 'fraction_numerical': 0.0038135593220338985, 'mean_word_length': 3.6752475247524754, 'pattern_counts': {'":': 0, '<': 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': '41904', 'n_tokens_mistral': 972, 'n_tokens_neox': 925, 'n_words': 209}