<commit_before>require 'pg'

module QC
  class Job
    attr_accessor :id, :details, :locked_at
    def initialize(args={})
      @id        = args["id"]
      @details   = args["details"]
      @locked_at = args["locked_at"]
    end

    def klass
      Kernel.const_get(details["job"].split(".").first)
    end

    def method
      details["job"].split(".").last
    end

    def params
      params = details["params"]
      if params.length == 1
        return params[0]
      else
        params
      end
    end

  end

  class DurableArray
    def initialize(args={})
      @connection = PGconn.connect(:dbname => "queue_classic_test")
      execute("SET client_min_messages TO 'warning'")
      execute("LISTEN jobs")
    end

    def <<(details)
      execute(
        "INSERT INTO jobs" +
        "(details)" +
        "VALUES ('#{details.to_json}')"
      )
      execute("NOTIFY jobs, 'new-job'")
    end

    def count
      execute("SELECT COUNT(*) from jobs")[0]["count"].to_i
    end

    def delete(job)
      execute("DELETE FROM jobs WHERE id = #{job.id}")
      job
    end<commit_msg>dang. left hard coded db url in durable_array class<commit_after>require 'pg'

module QC
  class Job
    attr_accessor :id, :details, :locked_at
    def initialize(args={})
      @id        = args["id"]
      @details   = args["details"]
      @locked_at = args["locked_at"]
    end

    def klass
      Kernel.const_get(details["job"].split(".").first)
    end

    def method
      details["job"].split(".").last
    end

    def params
      params = details["params"]
      if params.length == 1
        return params[0]
      else
        params
      end
    end

  end

  class DurableArray
    def initialize(args={})
      @connection = PGconn.connect(:dbname => args[:dbname])
      execute("SET client_min_messages TO 'warning'")
      execute("LISTEN jobs")
    end

    def <<(details)
      execute(
        "INSERT INTO jobs" +
        "(details)" +
        "VALUES ('#{details.to_json}')"
      )
      execute("NOTIFY jobs, 'new-job'")
    end

    def count
      execute("SELECT COUNT(*) from jobs")[0]["count"].to_i
    end

    def delete(job)
      execute("DELETE FROM jobs WHERE id = #{job.id}")
      job
    end
{'fraction_non_alphanumeric': 0.13464110566205975, 'fraction_numerical': 0.0026749888542131075, 'mean_word_length': 2.178470254957507, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5197040', 'n_tokens_mistral': 719, 'n_tokens_neox': 693, 'n_words': 177}