<commit_before>require 'redis'
require 'attention/version'
require 'attention/redis_pool'
require 'attention/subscriber'
require 'attention/instance'
require 'attention/timer'

module Attention
  class << self
    attr_accessor :options
    attr_reader :instance
  end

  self.options = {
    namespace: 'attention',                # Redis key namespace
    ttl: 60,                               # Heartbeat TTL in seconds
    redis_url: 'redis://localhost:6379/0', # Redis connection string
    pool_size: 5,                          # Size of the publishing Redis pool
    timeout: 5                             # Redis connection timeout
  }

  def self.redis
    RedisPool.instance
  end

  def self.activate(ip: nil, port: nil)
    @instance ||= Instance.new ip: ip, port: port
    instance.publish
  end

  def self.deactivate
    @instance.unpublish if @instance
  end

  def self.instances
    resolve info_for instance_keys
  end

  def self.instance_keys
    redis.call.keys 'instance_*'<commit_msg>Don't publish if the instance is already activated<commit_after>require 'redis'
require 'attention/version'
require 'attention/redis_pool'
require 'attention/subscriber'
require 'attention/instance'
require 'attention/timer'

module Attention
  class << self
    attr_accessor :options
    attr_reader :instance
  end

  self.options = {
    namespace: 'attention',                # Redis key namespace
    ttl: 60,                               # Heartbeat TTL in seconds
    redis_url: 'redis://localhost:6379/0', # Redis connection string
    pool_size: 5,                          # Size of the publishing Redis pool
    timeout: 5                             # Redis connection timeout
  }

  def self.redis
    RedisPool.instance
  end

  def self.activate(ip: nil, port: nil)
    return if @instance
    @instance = Instance.new ip: ip, port: port
    instance.publish
  end

  def self.deactivate
    @instance.unpublish if @instance
  end

  def self.instances
    resolve info_for instance_keys
  end

  def self.instance_keys
    redis.call.keys 'instance_*'
{'fraction_non_alphanumeric': 0.075998075998076, 'fraction_numerical': 0.008658008658008658, 'mean_word_length': 2.42668863261944, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '757788', 'n_tokens_mistral': 627, 'n_tokens_neox': 589, 'n_words': 177}