Skip to content

Hooks

Flux Importer registers two EmDash hooks, plugin:activate and cron. Together they run schedules and the hourly cleanup. It doesn't hook into content, media or anything else.

Flux Importer only does work when you ask for it (in the admin, the API or an agent tool) or when one of its scheduled tasks fires. It registers no content, media or comment hooks, so editing an entry never triggers it, and it registers no plugin:install, plugin:deactivate or plugin:uninstall hook.

The other way round works: imports write through EmDash’s content handlers, so another plugin’s content hooks run for imported entries. See For other plugins.

Hook When EmDash runs it What Flux Importer does
plugin:activate When the plugin is enabled: after install, and when it’s re-enabled Repairs its scheduled tasks from storage.
cron When one of its scheduled tasks fires Runs that task: retention, pump or schedule-<id>. Timeout: 180 seconds.

Flux Importer schedules its tasks with EmDash’s ctx.cron. EmDash evaluates every cron expression in UTC, on every host.

Task Schedule Exists when What it does
retention 17 * * * *: hourly, at minute 17 Always Deletes expired jobs and staged files, then repairs the other tasks.
schedule-<id> The schedule’s own cron expression While that schedule is enabled Marks the schedule due and starts the pump.
pump */10 * * * * *: every 10 seconds While a schedule is due or a scheduled job is still running Moves scheduled imports forward, one unit of work per tick.

The hourly cleanup, at minute 17 so it stays clear of EmDash’s own hourly maintenance at minute 0. It reads Keep import logs for (days) and deletes the finished jobs and staged files older than that. Storage lists exactly what it deletes and keeps.

After the cleanup it repairs the task list, whether the cleanup worked or not. It logs Removed expired import data with the counts, and Repaired the schedule tasks when it had to fix something.

One task per enabled schedule, named after the schedule’s ID. It doesn’t fetch or import anything itself: it marks the schedule due and makes sure the pump is running. A schedule that is already due keeps its earlier mark, so a slow run never stacks up launches. If the schedule was deleted or disabled, the task cancels itself.

The pump does the scheduled work, one unit per tick, so each tick stays short:

  1. Stands down while the site is fenced: while an EmDash site import or export is running, or media usage is being captured. Nothing runs until it’s clear.
  2. Finalizes up to two finished scheduled jobs: writes the run into the schedule’s log and pauses the schedule when the run failed, was cancelled, found an empty feed or had its missing entries refused.
  3. Runs one batch of the oldest scheduled job that’s still running, unless one of its batches is already running (for example because an Administrator is watching it in the admin).
  4. Otherwise launches at most one due schedule: fetches its URL source and, if the data changed, creates the job.
  5. When there’s nothing left to do, cancels itself. The next schedule-<id> task starts it again.

Scheduled batches run without a user, so their writes aren’t attributed to anyone. Before each launch, the pump checks that the Administrator who last turned the schedule on (created it, resumed it or changed what it runs) still exists and can import. See Schedules.

EmDash’s task list can drift from Flux Importer’s schedules: a deploy to a new database, a task EmDash refused, a schedule changed while the plugin was disabled. Reconciling fixes that from what’s in plugin storage:

  • Every enabled schedule gets its schedule-<id> task with its current expression.
  • A schedule-<id> task with no enabled schedule is cancelled.
  • The pump is started when a schedule is due or a scheduled job is still open.
  • retention is scheduled at 17 * * * *. A daily retention task left by a version before 0.4.0 moves to hourly.

Reconciling runs in plugin:activate, at the end of every hourly retention run, and when you change schedules on the Schedules tab. A schedule whose task couldn’t be set is logged by its ID and tried again at the next repair.

plugin:activate never fails the activation: EmDash disables a plugin, and its tasks, when activation throws. An error is logged instead (fluximporter: activation could not repair the schedule tasks: …), and the hourly repair tries again.

An expected failure, such as a feed that couldn’t be fetched, is recorded on its schedule and shows on the Schedules tab. It’s not thrown. An unexpected error is logged as fluximporter: cron task <name> failed and thrown again with its message only, with staged file IDs replaced by [staged file]. EmDash logs it, and a recurring task runs again at its next time.

How often the tasks really run depends on how EmDash’s scheduler runs on your host.

Node. EmDash’s built-in scheduler runs while the Node process runs. The pump ticks every 10 seconds, and each tick runs a batch of the job’s own batchSize. Keep at least one process running: while every process is stopped or asleep, schedules don’t fire and scheduled imports wait.

Cloudflare Workers. Plugin tasks run from the Worker’s scheduled handler, on the Cron Trigger in wrangler.jsonc. The starter templates use * * * * *, so the pump ticks once a minute, not every 10 seconds, and each tick runs a smaller batch to stay within the Worker’s limits. Without the Cron Trigger and the scheduled handler from @emdash-cms/cloudflare/worker, no plugin task runs at all: no schedules and no cleanup. Preview deployments run no Cron Triggers. EmDash’s Cloudflare deployment guide shows the setup, and emdash doctor checks it.

A schedule’s expression uses five fields (minute, hour, day of month, month, day of week) or one of @hourly, @daily, @weekly, @monthly and @yearly. A schedule can’t run more than once a minute, and on Cloudflare its launch waits for the next trigger.

Imports you start in the admin or through an agent don’t use these tasks: their batches run when the Run step or the agent asks for them. See Job states.