Zizq.Filter (Zizq v0.8.0)

Copy Markdown View Source

Filters shared by every endpoint that selects jobs.

Zizq.list_jobs/2, Zizq.count_jobs/2 and the bulk operations all narrow the same way, so the vocabulary is described once here.

Zizq.count_jobs([queue: "emails", status: [:ready, :scheduled]], MyApp.Zizq)

Options

  • :id — one job id, or a list of them.
  • :queue — one queue name, or a list.
  • :type — one job type, or a list.
  • :status — one status atom, or a list.
  • :budgets_key — one budget key, or a list. Matches a job bound to any of them.
  • :priority — a number, a Range, or [min: _, max: _].
  • :ready_at — the same, over DateTimes or milliseconds.
  • :attempts — the same, over attempt counts.
  • :filter — a jq expression run against each payload, e.g. ".user_id == 42".

An option left out does not narrow anything. A list matches any of its members, so status: [:ready, :scheduled] finds jobs in either.

Ranges

Ranges are inclusive at both ends. A bare number matches exactly:

priority: 5           # exactly 5
priority: 1..10       # 1 to 10
priority: [min: 5]    # 5 and above
priority: [max: 5]    # 5 and below

:ready_at accepts DateTimes as well as milliseconds, so a window reads as one:

ready_at: [min: DateTime.utc_now()]

Budgets

:budgets_key selects by what a job is bound to, which is useful for finding what is holding a budget in use — Zizq.delete_budget/2 refuses while anything remains bound:

Zizq.query(MyApp.Zizq)
|> Zizq.Query.where(budgets_key: "emails")
|> Zizq.Query.unbind_budget("emails")

Summary

Functions

Whether these filters can match nothing at all.

Functions

matches_nothing?(filters)

@spec matches_nothing?(keyword() | map()) :: boolean()

Whether these filters can match nothing at all.

A set filter given an empty list selects no jobs, but omitting it from the query string would select every job — so the two must not be confused. Callers check this and answer their own zero rather than sending a request:

Zizq.delete_all_jobs([queue: []], MyApp.Zizq)   # => {:ok, 0}

This matters most where the list is computed. queue: Enum.filter(...) coming back empty must delete nothing, not everything.

An empty string counts the same way, since it encodes to the same absent parameter.