<commit_before>package com.twitter.gizzard

import com.twitter.ostrich.StatsProvider
import com.twitter.xrayspecs.Time
import com.twitter.xrayspecs.TimeConversions._
import net.lag.configgy.{Config, ConfigMap}
import net.lag.kestrel.{PersistentQueue, QItem}
import net.lag.logging.Logger


class KestrelMessageQueue(queueName: String, config: ConfigMap, val jobParser: jobs.JobParser,
                          badJobsLogger: String => Unit, stats: Option[StatsProvider])
  extends MessageQueue {

  val log = Logger.get(getClass.getName)
  val TIMEOUT = 100

  def this(queueName: String, jobProcessor: jobs.JobParser, badJobsLogger: String => Unit) =
    this(queueName, Config.fromMap(Map.empty), jobProcessor, badJobsLogger, None)

  var queue = new PersistentQueue(config("path", "/tmp"), queueName, config)
  queue.setup()

  /** Length (in items) of this queue. */
  def size = queue.length.toInt

  /** Age (in seconds) of items in this queue. */
  def age = queue.currentAge / 1000.0

  def put(value: jobs.Schedulable) = {
    val message = value.toJson
    val startTime = Time.now
    if (!queue.add(message.getBytes)) throw new Exception("Unable to add job to queue")
    stats.map {
      _.addTiming("kestrel-put-timing", (Time.now - startTime).inMillis.toInt)
    }
  }

  def isShutdown = queue.isClosed<commit_msg>put the queue stats back. it's silly to have them anywhere else.<commit_after>package com.twitter.gizzard

import com.twitter.ostrich.{Stats, StatsProvider}
import com.twitter.xrayspecs.Time
import com.twitter.xrayspecs.TimeConversions._
import net.lag.configgy.{Config, ConfigMap}
import net.lag.kestrel.{PersistentQueue, QItem}
import net.lag.logging.Logger


class KestrelMessageQueue(queueName: String, config: ConfigMap, val jobParser: jobs.JobParser,
                          badJobsLogger: String => Unit, stats: Option[StatsProvider])
  extends MessageQueue {

  val log = Logger.get(getClass.getName)
  val TIMEOUT = 100

  def this(queueName: String, jobProcessor: jobs.JobParser, badJobsLogger: String => Unit) =
    this(queueName, Config.fromMap(Map.empty), jobProcessor, badJobsLogger, None)

  var queue = new PersistentQueue(config("path", "/tmp"), queueName, config)
  queue.setup()

  Stats.makeGauge(queueName + "_items") { size }
  Stats.makeGauge(queueName + "_age") { age }

  /** Length (in items) of this queue. */
  def size = queue.length.toInt

  /** Age (in seconds) of items in this queue. */
  def age = queue.currentAge / 1000.0

  def put(value: jobs.Schedulable) = {
    val message = value.toJson
    val startTime = Time.now
    if (!queue.add(message.getBytes)) throw new Exception("Unable to add job to queue")
    stats.map {
      _.addTiming("kestrel-put-timing", (Time.now - startTime).inMillis.toInt)
    }
  }

  def isShutdown = queue.isClosed
{'fraction_non_alphanumeric': 0.11702127659574468, 'fraction_numerical': 0.005673758865248227, 'mean_word_length': 3.863793103448276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6985790', 'n_tokens_mistral': 923, 'n_tokens_neox': 883, 'n_words': 227}