<commit_before>package main

import (
	"fmt"
	"time"

	"github.com/garyburd/redigo/redis"
)

const (
	LOG_SEQ_KEY string = "QMD_LOG_IDS"
	LOGLIMIT    int    = 50
)

func newRedisPool(server string) *redis.Pool {
	return &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			con, err := redis.Dial("tcp", server)
			if err != nil {
				return nil, err
			}
			return con, err
		},
		TestOnBorrow: func(con redis.Conn, t time.Time) error {
			_, err := con.Do("PING")
			return err
		},
	}
}

func setRedisID(id int) (bool, error) {
	conn := redisDB.Get()
	defer conn.Close()

	var result bool
	key := fmt.Sprintf("Job #%d", id)
	success, err := redis.Bool(conn.Do("SETNX", key, id))
	if err != nil {
		log.Error(err.Error())
		return result, err
	}
	if success {
		result = true
		conn.Do("EXPIRE", key, 900)
	}
	return result, nil
}

func unsetRedisID(id int) (bool, error) {
	conn := redisDB.Get()
	defer conn.Close()

	var result bool
	numRemoved, err := redis.Int(conn.Do("DEL", fmt.Sprintf("Job #%d", id)))
	if err != nil {
		log.Error(err.Error())
		return result, err
	}
	if numRemoved > 0 {
		result = true
	}
	return result, nil
}

func getRedisID() (int, error) {
	conn := redisDB.Get()
	defer conn.Close()

	id, err := redis.Int(conn.Do("INCR", LOG_SEQ_KEY))<commit_msg>Moved Job Timeout to a constant.<commit_after>package main

import (
	"fmt"
	"time"

	"github.com/garyburd/redigo/redis"
)

const (
	LOG_SEQ_KEY string = "QMD_LOG_IDS"
	LOGLIMIT    int    = 50
	JOB_TIMEOUT int    = 900
)

func newRedisPool(server string) *redis.Pool {
	return &redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			con, err := redis.Dial("tcp", server)
			if err != nil {
				return nil, err
			}
			return con, err
		},
		TestOnBorrow: func(con redis.Conn, t time.Time) error {
			_, err := con.Do("PING")
			return err
		},
	}
}

func setRedisID(id int) (bool, error) {
	conn := redisDB.Get()
	defer conn.Close()

	var result bool
	key := fmt.Sprintf("Job #%d", id)
	success, err := redis.Bool(conn.Do("SETNX", key, id))
	if err != nil {
		log.Error(err.Error())
		return result, err
	}
	if success {
		result = true
		conn.Do("EXPIRE", key, JOB_TIMEOUT)
	}
	return result, nil
}

func unsetRedisID(id int) (bool, error) {
	conn := redisDB.Get()
	defer conn.Close()

	var result bool
	numRemoved, err := redis.Int(conn.Do("DEL", fmt.Sprintf("Job #%d", id)))
	if err != nil {
		log.Error(err.Error())
		return result, err
	}
	if numRemoved > 0 {
		result = true
	}
	return result, nil
}

func getRedisID() (int, error) {
	conn := redisDB.Get()
	defer conn.Close()

	id, err := redis.Int(conn.Do("INCR", LOG_SEQ_KEY))
{'fraction_non_alphanumeric': 0.1598526703499079, 'fraction_numerical': 0.007366482504604052, 'mean_word_length': 3.331738437001595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1575336', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1102, 'n_words': 275}