Search documentation of phoenix_kit

# PhoenixKit.Sitemap.SchedulerWorker (phoenix_kit v1.6.19)

View Source

Oban worker for scheduled sitemap regeneration.

This worker is responsible for:

- Periodic sitemap regeneration based on configured interval
- Automatic re-scheduling after each run
- Checking if scheduling is enabled before execution

## Configuration

Scheduling is controlled via Settings:

- `sitemap_schedule_enabled` - Enable/disable automatic regeneration
- `sitemap_schedule_interval_hours` - Interval between regenerations (default: 24)

## Usage

    # Schedule initial job (called when schedule is enabled)
    PhoenixKit.Sitemap.SchedulerWorker.schedule()

    # Manual trigger
    PhoenixKit.Sitemap.SchedulerWorker.regenerate_now()

    # Cancel scheduled jobs
    PhoenixKit.Sitemap.SchedulerWorker.cancel_scheduled()

## Oban Queue

Jobs are placed in the `:sitemap` queue with max 3 attempts.

# Summary

## Functions

cancel_scheduled()

Cancels all scheduled sitemap jobs.

perform(job)

Performs sitemap regeneration.

regenerate_now()

Triggers immediate sitemap regeneration.

schedule(opts \\ [])

Schedules the next sitemap regeneration.

schedule_next()

Schedules the next regeneration after current job completes.

status()

Returns the current scheduling status and next run time.

# Functions

# cancel_scheduled()

    @spec cancel_scheduled() :: {:ok, non_neg_integer()}

Cancels all scheduled sitemap jobs.

This is called when scheduling is disabled.

# perform(job)

Performs sitemap regeneration.

This callback is invoked by Oban when the scheduled job runs. It checks if scheduling is still enabled before regenerating.

# regenerate_now()

    @spec regenerate_now() :: {:ok, Oban.Job.t()} | {:error, term()}

Triggers immediate sitemap regeneration.

This creates a job that runs immediately, bypassing the schedule.

# schedule(opts \\ [])

    @spec schedule(keyword()) :: {:ok, Oban.Job.t()} | {:error, term()} | :disabled

Schedules the next sitemap regeneration.

The job is scheduled based on `sitemap_schedule_interval_hours` setting. If scheduling is disabled, no job is created.

## Options

- `:delay_hours` - Override the configured interval (optional)

## Examples

    # Schedule with configured interval
    PhoenixKit.Sitemap.SchedulerWorker.schedule()

    # Schedule with custom delay
    PhoenixKit.Sitemap.SchedulerWorker.schedule(delay_hours: 1)

# schedule_next()

    @spec schedule_next() :: {:ok, Oban.Job.t()} | {:error, term()} | :disabled

Schedules the next regeneration after current job completes.

# status()

    @spec status() :: map()

Returns the current scheduling status and next run time.