<commit_before>require 'kintama'
require 'moneta'
require 'daybreak'
require 'redislike'

class ResilientQueue
  attr_reader :db
  def initialize(options = {})
    @name = options.fetch :name, 'default'
    @timeout = options.fetch :timeout, 60
    @pending = "#{@name}:pending"
    @claimed = "#{@name}:claimed"
    @db = Moneta.new :Daybreak, expires: true, file: ".#{@name}.db"
  end

  def create_id
    @db.increment "#{@name}:id_count"
  end

  def enqueue(item)
    id = create_id
    @db.store "#{@name}:#{id}", item, expires: @timeout
    @db.lpush @pending, id
  end

  def dequeue
    # TODO: requeuing
    id = @db.rpoplpush @pending, @claimed
    @db.fetch "#{@name}:#{id}"
  end
end<commit_msg>Abstract the key string<commit_after>require 'kintama'
require 'moneta'
require 'daybreak'
require 'redislike'

class ResilientQueue
  attr_reader :db
  def initialize(options = {})
    @name = options.fetch :name, 'default'
    @timeout = options.fetch :timeout, 60
    @pending = "#{@name}:pending"
    @claimed = "#{@name}:claimed"
    @db = Moneta.new :Daybreak, expires: true, file: ".#{@name}.db"
  end

  def create_id
    @db.increment "#{@name}:id_count"
  end

  def key(id)
    "#{@name}:@{id}"
  end

  def enqueue(item)
    id = create_id
    @db.store key(id), item, expires: @timeout
    @db.lpush @pending, id
  end

  def dequeue
    # TODO: requeuing
    id = @db.rpoplpush @pending, @claimed
    @db.fetch key(id)
  end
end
{'fraction_non_alphanumeric': 0.15586206896551724, 'fraction_numerical': 0.002758620689655172, 'mean_word_length': 3.4922600619195046, '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': '199779', 'n_tokens_mistral': 543, 'n_tokens_neox': 532, 'n_words': 134}