Skip to content

This is a standalone demo plugin that showcases WP-Queue capabilities with real-world examples for blogs and e-commerce.

Notifications You must be signed in to change notification settings

rwsite/wp-queue-example-plugin

Repository files navigation

WP-Queue Demo Examples

This is a standalone demo plugin that showcases WP-Queue capabilities with real-world examples for blogs and e-commerce. It provides both code examples for developers and an interactive UI for users.

WP-Queue Demo dashboard

Prerequisites

  • WP-Queue plugin must be installed and activated
  • WordPress 6.0+
  • PHP 8.3+

Installation

  1. Install and activate the WP-Queue plugin first
  2. Download and install this demo plugin
  3. Activate WP-Queue Demo Examples
  4. Access the interactive dashboard at WP Admin → WP-Queue Demo

What the examples demonstrate

Example 1: Batch data processing (simple)

Blog/IM task: Write array of messages to log file for audit actions.

  • Features: Processing array data in a single job.
  • Call: ?example_job=log_batch — creates and writes 3 test messages to wp-content/batch-log.txt.

Example 2: Batch processing by cron with retry (medium)

E-commerce task: Send marketing emails to customers.

  • Features:
    • Run every 10 minutes via #[Schedule('10min')].
    • Retry up to 5 times on error via #[Retries(5)].
    • Timeout 60 sec via #[Timeout(60)].
  • Call: ?example_job=email_batch — test dispatch (replace emails with real ones).

Example 3: Complex batch processing (complex)

Blog task: Automatic publication of posts from drafts + notification of subscribers.

  • Features:
    • Daily run via #[Schedule('daily')].
    • Retry 3 times on email sending error.
    • Creates posts, sends notifications, writes report to batch-report.log.
  • Call: ?example_job=publish_batch — creates 2 posts and sends emails.

Example 4: Job chain with unique jobs

Blog task: New user registration with greeting and subscription.

  • Features:
    • Chain: create user → send email → add to newsletter.
    • Unique jobs via #[UniqueJob] prevent duplication.
  • Call: ?example_job=user_register — creates test user.

Example 5: Monitoring with custom intervals and queue pause

E-commerce task: Automatic inventory monitoring and reordering.

  • Features:
    • Custom interval every 2 hours via #[Schedule('2hourly')].
    • Queue pause if supplier is offline (night time).
    • Automatic reordering when stock is low.
  • Call: ?example_job=inventory_check — manual check (usually by cron).

Example 6: Synchronization with external APIs

E-commerce task: Synchronization of order statuses with delivery service.

  • Features:
    • Run every 15 minutes with retry on API errors.
    • Handling network errors and service unavailability.
    • Updating order statuses in WooCommerce.
  • Call: ?example_job=order_sync — manual synchronization.

Example 7: Importing large data with pagination

E-commerce task: Importing product catalog from CSV file.

  • Features:
    • Process file in chunks (pagination) to avoid overloading DB.
    • Recursive dispatch of next pages with delay.
    • Creating WooCommerce products.
  • Call: ?example_job=product_import — needs file wp-content/products.csv.

Example 8: Monitoring and event system

E-commerce task: Sales analysis and sending alerts on problems.

  • Features:
    • Hourly analysis of last hour sales.
    • Logging via events (wp_queue_job_processed, wp_queue_job_failed).
    • Sending alerts to admin on low sales.
  • Call: ?example_job=sales_report — generate sales report.

Interactive Demo Dashboard

The plugin includes a comprehensive visual dashboard accessible via WP Admin → WP-Queue Demo that provides:

  • Interactive job cards for each example with visual status indicators
  • One-click job execution with real-time status updates
  • Progress monitoring with animated status changes (Ready → Queued → Running → Completed/Failed)
  • Activity logs with auto-refresh showing job processing activity
  • Color-coded complexity levels (Simple/Medium/Complex)
  • Responsive design that works on all devices

Dashboard Features

  • Status Indicators: Visual badges showing job states with animations
  • AJAX Updates: Real-time status polling without page refreshes
  • Error Handling: Clear error messages and status updates
  • Log Monitoring: Live activity feed with scrollable log container
  • Batch Operations: Run multiple examples and track their progress simultaneously

The dashboard makes it easy to demonstrate and test all WP-Queue capabilities interactively!

Files

  • example-plugin.php – main plugin file with dependency checks and initialization.
  • admin-page.php – visual demo dashboard with interactive controls.
  • assets/css/demo.css – styling for the demo dashboard.
  • assets/js/demo.js – JavaScript for interactive job execution and monitoring.
  • Jobs/BatchLogJob.php – Example 1: array data processing.
  • Jobs/BatchEmailJob.php – Example 2: sending emails with cron and retry.
  • Jobs/BatchPublishAndNotifyJob.php – Example 3: publishing posts + emails + report.
  • Jobs/UserRegistrationJobs.php – Example 4: registration chain with unique jobs.
  • Jobs/InventoryJobs.php – Example 5: inventory monitoring with custom intervals.
  • Jobs/OrderSyncJob.php – Example 6: synchronization with external APIs.
  • Jobs/ProductImportJob.php – Example 7: import with pagination.
  • Jobs/SalesMonitoringJob.php – Example 8: monitoring with events.
  • manual-dispatch.php – 8 manual dispatch examples.

For Developers

Each job class demonstrates different WP-Queue features:

  • Attributes: #[Schedule], #[Queue], #[Retries], #[Timeout], #[UniqueJob]
  • Base Job Class: Extends WPQueue\Jobs\Job with minimal boilerplate
  • Error Handling: Retry logic and exception handling
  • Event System: Integration with WP-Queue events
  • Real-world Patterns: Common e-commerce and blog automation tasks

All comments in the code contain step-by-step explanations so you understand what and why it's done.

About

This is a standalone demo plugin that showcases WP-Queue capabilities with real-world examples for blogs and e-commerce.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published