Automation & Scheduling

Background Cron vs Event-Specific Cron Configuration

Guide to configuring global background cron processing vs isolated per-import scheduled cron events.

Frexten Engineering Team
Updated 2026-11-20

NextGen Smart Data Importer supports two distinct cron execution models:

  1. Background Cron (Global / Polling): Processes queued media downloads, daily retention cleanup, and all due/queued imports using a global master token or WP-Cron.
  2. Event-Specific / Import-Specific Cron: Targets a single import job using its own schedule (nextgen_run_scheduled_import_hook), its own per-import cron_secret_key, or direct sync/run REST triggers.

1. Background Cron (Global Queue & Maintenance)

What It Handles

  • Queued Media Downloads (NextGen_Image_Processor::process_queue()):
    • Processes up to 50 pending rows per run from wp_nextgen_image_queue (protected by nextgen_image_queue_lock and a 30s download timeout).
    • Runs automatically on WP-Cron hook nextgen_image_processor_cron and at the start of every /cron/process external cron call.
  • Global Scheduled & Queued Imports (get_next_import_to_process($token, true)):
    • When triggered with the Global External Cron Secret Key, processes due scheduled imports and queued imports that do not override the global token, including remote sync (ftp, sftp, s3, google_sheets).
  • Daily Retention Cleanup (nextgen_importer_daily_maintenance):
    • WP-Cron daily hook registered by NextGen_Retention_Worker for log/data retention maintenance.

How to Configure Background Cron

Step 1: Set Up the Global External Cron Key (Pro)

  1. Go to NextGen Importer → Global Settings → External Cron.
  2. Copy or generate your Cron Secret Key (cron.secret_key).
  3. Configure your preferred Time Limit (cron.time_limit, default 120s) and optional Sleep (cron.sleep).
  4. Click Save Settings.

Step 2: Add the Cron Job on Your Server

Use the rest_route URL format with &token= and double quotes "...":

  • SSH / crontab -e (full line, runs every minute):
cron
* * * * * /usr/bin/curl -s "https://yoursite.com/index.php?rest_route=/nextgen-importer/v1/cron/process&token=YOUR_GLOBAL_SECRET_KEY" > /dev/null 2>&1

(Run which curl over SSH if your server installs curl at a custom path.)

  • cPanel / DirectAdmin / Hostinger Cron UI (command only):
    1. Select Once Per Minute (* * * * *) in the panel's schedule dropdowns.
    2. Paste only the command:
bash
curl -s "https://yoursite.com/index.php?rest_route=/nextgen-importer/v1/cron/process&token=YOUR_GLOBAL_SECRET_KEY" > /dev/null 2>&1
  • External URL Monitors (EasyCron, UptimeRobot, Plesk "Fetch a URL"):
text
https://yoursite.com/index.php?rest_route=/nextgen-importer/v1/cron/process&token=YOUR_GLOBAL_SECRET_KEY

2. Event-Specific / Import-Specific Cron

What It Handles

Use event-specific cron when a particular import needs its own isolated schedule, remote sync cadence, or dedicated security token—without triggering other imports.

  1. Per-Import External Cron Token (cron_secret_key):
    • Each import can define its own cron_secret_key in Import Settings (Step 3).
    • verify_cron_token() and validate_import_token() in NextGen_Pro_Scheduler scope /cron/process&token=IMPORT_SECRET_KEY specifically to that import.
  2. Per-Import WP-Cron Schedule (nextgen_run_scheduled_import_hook):
    • Scheduled per import via the Schedule action (/nextgen-importer/v1/schedule) or auto-resume (/nextgen-importer/v1/schedule-resume/{import_id}).
    • On completion, fires nextgen_pro_finalize_scheduled_import.
  3. Direct On-Demand Event Triggers (REST API):
    • /nextgen-importer/v1/sync-run-import/{import_id} and /nextgen-importer/v1/sync-and-run/{import_id} trigger a specific import immediately (useful for webhooks, CI/CD, or external automation).

How to Configure Event-Specific Cron

  1. Start or open an import and go to Step 3: Import Settings → Cron / Scheduling.
  2. Set a unique Import Cron Secret Key (cron_secret_key) for that specific import (or leave blank to use the Global token).
  3. Copy the command shown in the External Cron Configuration Guide inside Import Settings.
  4. Add it to your server cron with your desired schedule (for example, every 15 minutes):
cron
*/15 * * * * /usr/bin/curl -s "https://yoursite.com/index.php?rest_route=/nextgen-importer/v1/cron/process&token=YOUR_IMPORT_SECRET_KEY" > /dev/null 2>&1
  • Only imports matching YOUR_IMPORT_SECRET_KEY (plus pending image queue items) will run when this cron fires.

Option B: WP-Cron Scheduled Import (No Server Crontab Required)

  1. In the plugin UI, configure the import's schedule interval (e.g., Hourly, Twice Daily, Daily) via the Schedule workflow (/schedule).
  2. WordPress schedules nextgen_run_scheduled_import_hook for that import_id.
  3. Note for low-traffic sites: WP-Cron only fires on incoming site visits unless you also ping wp-cron.php or use Option A (External Cron).

3. Comparison Summary

Feature Background Cron (Global) Event-Specific Cron (Per-Import)
Token Used Global cron.secret_key Per-import cron_secret_key (or WP-Cron import_id hook)
Scope All due/queued imports (without override) + image queue Only the matching import (+ image queue)
Media Queue Processed automatically (NextGen_Image_Processor) Processed automatically on /cron/process
Daily Cleanup nextgen_importer_daily_maintenance (WP-Cron) Handled by background retention worker
Best For One master * * * * * cron handling all site imports & images Dedicated schedules, isolated client feeds, or webhook triggers

4. Essential Checklist for Both Modes

  • Always use index.php?rest_route=/nextgen-importer/v1/cron/process&token=... (with &token=, never a second ?token=).
  • Always wrap the URL in double quotes "..." in crontab -e so & is not interpreted by the shell.
  • Click Save Settings after generating or changing a Global or per-import token so the database matches your cron command (otherwise /cron/process returns 403 Forbidden).