<commit_before>package contractor

import (
	"time"
)

const (
	// uptimeInterval specifies how frequently hosts are checked.
	uptimeInterval = 30 * time.Minute
)

// threadedMonitorUptime regularly checks host uptime, and deletes contracts
// whose hosts fall below a minimum uptime threshold.
func (c *Contractor) threadedMonitorUptime() {
	for range time.Tick(uptimeInterval) {
		// get current contracts
		contracts := c.Contracts()

		// identify hosts with poor uptime
		badContracts := contracts[:0] // reuse memory during filter
		for _, contract := range contracts {
			if c.hdb.IsOffline(contract.NetAddress) {
				badContracts = append(badContracts, contract)
			}
		}
		if len(badContracts) == 0 {
			// nothing to do
			continue
		}

		// delete contracts with bad hosts. When a new block arrives,
		// ProcessConsensusChange will take care of forming new contracts as
		// needed.
		c.editLock.Lock()
		c.mu.Lock()
		for _, contract := range badContracts {
			delete(c.contracts, contract.ID)
		}
		c.mu.Unlock()
		c.editLock.Unlock()
		c.log.Println("INFO: deleted %v contracts because their hosts were offline", len(badContracts))
	}
}<commit_msg>make uptimeInterval a build var<commit_after>package contractor

import (
	"time"

	"github.com/NebulousLabs/Sia/build"
)

// uptimeInterval specifies how frequently hosts are checked.
var uptimeInterval = func() time.Duration {
	switch build.Release {
	case "dev":
		return 1 * time.Minute
	case "standard":
		return 30 * time.Minute
	case "testing":
		return 100 * time.Millisecond
	}
	panic("undefined uptimeInterval")
}()

// threadedMonitorUptime regularly checks host uptime, and deletes contracts
// whose hosts fall below a minimum uptime threshold.
func (c *Contractor) threadedMonitorUptime() {
	for range time.Tick(uptimeInterval) {
		// get current contracts
		contracts := c.Contracts()

		// identify hosts with poor uptime
		badContracts := contracts[:0] // reuse memory during filter
		for _, contract := range contracts {
			if c.hdb.IsOffline(contract.NetAddress) {
				badContracts = append(badContracts, contract)
			}
		}
		if len(badContracts) == 0 {
			// nothing to do
			continue
		}

		// delete contracts with bad hosts. When a new block arrives,
		// ProcessConsensusChange will take care of forming new contracts as
		// needed.
		c.editLock.Lock()
		c.mu.Lock()
		for _, contract := range badContracts {
			delete(c.contracts, contract.ID)
		}
		c.mu.Unlock()
		c.editLock.Unlock()
		c.log.Printf("INFO: deleted %v contracts because their hosts were offline", len(badContracts))
	}
}
{'fraction_non_alphanumeric': 0.10442546583850931, 'fraction_numerical': 0.004658385093167702, 'mean_word_length': 3.6600361663652805, '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': '2746046', 'n_tokens_mistral': 886, 'n_tokens_neox': 782, 'n_words': 244}