# `Que.Persistence`
[🔗](https://github.com/sheharyarn/que/blob/main/lib/que/persistence/persistence.ex#L1)

Provides a high-level API to interact with Jobs in Database

This module is a behaviour that delegates calls to the specified
adapter. It has been designed in a way that it's easy to write
custom adapters for other databases or stores like Redis, even
though there are no current plans on supporting anything other
than `Mnesia`.

# `all`

```elixir
@callback all() :: [Que.Job.t()]
```

Returns all `Que.Job`s in the database.

# `all`

```elixir
@callback all(worker :: Que.Worker.t()) :: [Que.Job.t()]
```

Returns all `Que.Job`s for the given worker.

# `completed`

```elixir
@callback completed() :: [Que.Job.t()]
```

Returns completed `Que.Job`s from the database.

# `completed`

```elixir
@callback completed(worker :: Que.Worker.t()) :: [Que.Job.t()]
```

Returns completed `Que.Job`s for the given worker.

# `destroy`

```elixir
@callback destroy(id :: integer()) :: :ok | no_return()
```

Deletes a `Que.Job` from the database.

# `failed`

```elixir
@callback failed() :: [Que.Job.t()]
```

Returns failed `Que.Job`s from the database.

# `failed`

```elixir
@callback failed(worker :: Que.Worker.t()) :: [Que.Job.t()]
```

Returns failed `Que.Job`s for the given worker.

# `find`

```elixir
@callback find(id :: integer()) :: Que.Job.t() | nil
```

Finds a `Que.Job` from the database.

Returns the a Job struct if it's found, otherwise `nil`.

# `incomplete`

```elixir
@callback incomplete() :: [Que.Job.t()]
```

Returns incomplete `Que.Job`s from the database.

This includes all Jobs whose status is either
`:queued` or `:started` but not `:failed`.

# `incomplete`

```elixir
@callback incomplete(worker :: Que.Worker.t()) :: [Que.Job.t()]
```

Returns incomplete `Que.Job`s for the given worker.

# `initialize`

```elixir
@callback initialize() :: :ok | :error
```

Makes sure that the Database is ready to be used.

This is called when the Que application, specifically
`Que.Server`, starts to make sure that a database exists
and is ready to be used.

# `insert`

```elixir
@callback insert(job :: Que.Job.t()) :: Que.Job.t()
```

Inserts a `Que.Job` into the database.

Returns the same Job struct with the `id` value set

# `update`

```elixir
@callback update(job :: Que.Job.t()) :: Que.Job.t()
```

Updates an existing `Que.Job` in the database.

This methods finds the job to update by the given
job's id. If no job with the given id exists, it is
inserted as-is. If the id of the given job is nil,
it's still inserted and a valid id is assigned.

Returns the updated job.

# `all`

# `all`

# `completed`

# `completed`

# `destroy`

# `failed`

# `failed`

# `find`

# `incomplete`

# `incomplete`

# `initialize`

# `insert`

# `update`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
