<commit_before>if Code.ensure_loaded?(Ecto) do

  defmodule Honeydew.EctoSource.SQL.Postgres do
    alias Honeydew.EctoSource
    alias Honeydew.EctoSource.SQL

    @behaviour SQL

    @impl true
    def integer_type do
      :bigint
    end

    @impl true
    def ready do
      SQL.far_in_the_past()
      |> time_in_msecs
      |> msecs_ago
    end

    @impl true
    def reserve(state) do
      "UPDATE #{state.table}
      SET #{state.lock_field} = #{now_msecs()}
      WHERE id = (
        SELECT id
        FROM #{state.table}
        WHERE #{state.lock_field} BETWEEN 0 AND #{msecs_ago(state.stale_timeout)}
        ORDER BY #{state.lock_field}, #{state.key_field}
        LIMIT 1
        FOR UPDATE
      )
      RETURNING #{state.key_field}, #{state.private_field}"
    end

    @impl true
    def cancel(state) do
      "UPDATE #{state.table}
      SET #{state.lock_field} = NULL
      WHERE
        id = $1
        AND #{state.lock_field} BETWEEN 0 AND #{msecs_ago(state.stale_timeout)}
      RETURNING #{state.lock_field}"
    end

    @impl true
    def status(state) do
      "SELECT COUNT(CASE WHEN #{state.lock_field} IS NOT NULL THEN 1 ELSE NULL END) AS count,<commit_msg>Ecto Poll Queue: Use SKIP LOCKED in Postgres<commit_after>if Code.ensure_loaded?(Ecto) do

  defmodule Honeydew.EctoSource.SQL.Postgres do
    alias Honeydew.EctoSource
    alias Honeydew.EctoSource.SQL

    @behaviour SQL

    @impl true
    def integer_type do
      :bigint
    end

    @impl true
    def ready do
      SQL.far_in_the_past()
      |> time_in_msecs
      |> msecs_ago
    end

    @impl true
    def reserve(state) do
      "UPDATE #{state.table}
      SET #{state.lock_field} = #{now_msecs()}
      WHERE id = (
        SELECT id
        FROM #{state.table}
        WHERE #{state.lock_field} BETWEEN 0 AND #{msecs_ago(state.stale_timeout)}
        ORDER BY #{state.lock_field}, #{state.key_field}
        LIMIT 1
        FOR UPDATE SKIP LOCKED
      )
      RETURNING #{state.key_field}, #{state.private_field}"
    end

    @impl true
    def cancel(state) do
      "UPDATE #{state.table}
      SET #{state.lock_field} = NULL
      WHERE
        id = $1
        AND #{state.lock_field} BETWEEN 0 AND #{msecs_ago(state.stale_timeout)}
      RETURNING #{state.lock_field}"
    end

    @impl true
    def status(state) do
      "SELECT COUNT(CASE WHEN #{state.lock_field} IS NOT NULL THEN 1 ELSE NULL END) AS count,
{'fraction_non_alphanumeric': 0.0984754841367944, 'fraction_numerical': 0.004120313143798929, 'mean_word_length': 2.3443526170798896, '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': '5616701', 'n_tokens_mistral': 869, 'n_tokens_neox': 814, 'n_words': 214}