=== FWP Scheduler ===
Contributors: farowp
Tags: cron, scheduler, scheduled tasks, queue, automation
Requires at least: 6.4
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.2.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

A task queue of its own plus a signed endpoint, so an external scheduler can run WordPress cron on time instead of waiting for visits.

== Description ==

WordPress has no real cron: it runs scheduled tasks when somebody visits the site. On a low-traffic site, a 9:00 task may run at 14:00, or never. And if the host blocks the site from calling itself, it never runs at all.

FWP Scheduler solves the half that belongs to the site:

* **Its own queue in the database** (`wp_faro_sch_tareas`), with due time, interval, attempts and an idempotency key.
* **Signed endpoint** `POST /wp-json/faro-scheduler/v1/tick`: the external scheduler pushes, the site runs one task per request and returns the result as JSON.
* **Per-row claim** with a lease: two processes cannot run the same task, and one stuck task does not block the rest.
* **Retries** with growing backoff and a final dead state when attempts run out.
* **Only registered actions**: it never runs arbitrary code.
* **Admin panel** with scheduler health, tasks by state, runs per hour and per day, and a filterable queue with actions.
* **WP-CLI**: `wp faro-scheduler lista|correr|encolar|estado|conexion`.

The external scheduler is the other half and is not part of this plugin: any program able to sign an HMAC-SHA256 request will do. FaroWP runs its own service that pushes every 30 seconds, records every run and sends a Telegram alert when a site stops answering.

== Installation ==

1. Upload the `faro-scheduler` folder to `/wp-content/plugins/` or install the ZIP from Plugins → Add New.
2. Activate the plugin. Tables and the signing secret are created.
3. Open FWP Scheduler → Settings and copy the push URL and the secret into your scheduler.
4. Create a task in FWP Scheduler → New task using an action already registered on the site.

== Frequently Asked Questions ==

= Does it replace WP-Cron? =

No. It coexists with it. You can leave WP-Cron enabled as a third safety net and use the queue for anything that needs an exact time.

= Do I need a separate server? =

Yes, for the pushing side. A small VPS, a Raspberry Pi or any machine with HTTPS access to the site will do. The scheduler is not bundled.

= What happens if the scheduler is off? =

Tasks wait in the queue. If you enable the safety net, each front-end visit runs one due task so nothing stays stuck.

= Can it run anything? =

Only WordPress actions already registered on the site (`do_action`). The endpoint accepts no code and no paths.

= Where is the secret stored? =

In the site options table, or in the `FARO_SCH_SECRET` constant if you define it in `wp-config.php`. It can be regenerated from Settings.

== Screenshots ==

1. Overview: scheduler health, tasks by state, and runs per hour and per day.
2. Task queue with state filters and run, retry and delete actions.
3. Settings: tasks per request, history retention, attempts, lease time and the safety net.
4. Scheduler connection: push URL, secret and regeneration.

== Changelog ==

= 0.2.4 =
* The plugin is now called FWP Scheduler on the website and in WordPress (the old Faro name is retired). Nothing changes under the hood: same slug, same options, same data.

= 0.2.3 =
* The Settings and New task screens now match the rest of the plugins: cards, per-field explanations and a status card on top.
* New Help tab: start in three steps, every setting explained (what it is and when to change it), creating tasks from code, and what to look at when a task does not run.
* Stylesheet extended for the help pieces (steps, comparison tables, status chips).

= 0.2.2 =
* The licence is sent when connecting the site, so the service knows the plan.
* Fix: version shown in the settings screen.

= 0.2.1 =
* Fix: failed tasks were never retried. The claim now picks up tasks in state "failed" whose backoff has expired.
* Fix: the run history recorded "pending" for successful recurring tasks; it now records "done".
* New: `wp faro-scheduler encolar --datos='{"key":"value"}'` to enqueue with arguments.

= 0.2.0 =
* New: connect the site to the Faro service with one click. No VPS, no Raspberry Pi, no hosting cron: Faro calls your site every 30 seconds.
* New: connection card in Settings with plan, site id and last call; disconnect button.
* The self-hosted scheduler stays available under "Use my own scheduler (advanced)".

= 0.1.1 =
* The overview now says "1 task" instead of "1 tasks".

= 0.1.0 =
* First release: own queue, signed endpoint, retries, admin panel and WP-CLI.

== Upgrade Notice ==

= 0.1.0 =
First release.
