Scheduling Automated Imports with Super Speedy Imports

Super Speedy Imports provides a powerful CLI command (wp ssi) that allows you to run imports from the command line. While this is useful for manual imports, you may want to automate your imports to run on a schedule. This guide will show you how to use crontab to schedule your imports to run automatically.

Understanding the Basic Import Command

The basic command to run an import is:

wp ssi [import_id] [stage]

Where:

  • [import_id] is the ID of your import (e.g., 1, 2, 3)
  • [stage] is optional and defaults to ‘all’ to run all stages

For example, to run import #1:

wp ssi 1

Setting Up a Basic Cron Job

Cron is a time-based job scheduler in Unix-like operating systems. You can use it to schedule commands to run periodically.

  1. Access your server via SSH or through your hosting provider’s terminal
  2. Open the crontab editor:
crontab -e

If this is your first time using crontab, you may be asked to choose an editor. If you’re not familiar with vim, choose nano (usually option 1).

  1. Add a line to schedule your import:
# Run import #1 every day at 2 AM
0 2 * * * cd /path/to/your/wordpress && wp ssi 1 > /path/to/logfile.log 2>&1

The cron schedule format is:

minute hour day-of-month month day-of-week command

Common schedule examples:

  • 0 2 * * * – Every day at 2 AM
  • 0 */6 * * * – Every 6 hours
  • 0 0 * * 0 – Every Sunday at midnight
  • 0 0 1 * * – First day of every month at midnight

Downloading a Remote File Before Import

If you need to download a file before running the import, you can chain commands using && (which runs the next command only if the previous one succeeds):

# Download file then run import #1 with the downloaded file
0 2 * * * cd /path/to/your/wordpress && wget -O /path/to/wordpress/wp-content/uploads/super-speedy-imports/latest-data.csv https://example.com/data-feed.csv && wp ssi 1 --file=latest-data.csv > /path/to/logfile.log 2>&1

The --file parameter tells Super Speedy Imports to use a specific CSV file instead of the one configured in the import settings.

Running Multiple Imports in Sequence

You can run multiple imports one after another by chaining commands:

Running Second Import Only if First Succeeds

Use the && operator to run the second import only if the first one completes successfully:

0 2 * * * cd /path/to/your/wordpress && wp ssi 1 && wp ssi 2 > /path/to/logfile.log 2>&1

Running Second Import Regardless of First Import’s Result

Use the ; operator to run the second import regardless of whether the first one succeeds:

0 2 * * * cd /path/to/your/wordpress && wp ssi 1; wp ssi 2 > /path/to/logfile.log 2>&1

Running WooCommerce Regeneration After Import

After your imports are complete, you may want to regenerate WooCommerce lookup tables to ensure your product data is properly indexed:

0 2 * * * cd /path/to/your/wordpress && wp ssi 1 && wp taxonomy list --field=name | xargs wp term recount && wp wc tool run regenerate_product_attributes_lookup_table --user=admin && wp wc tool run clear_transients --user=admin && wp wc tool run regenerate_product_lookup_tables --user=admin > /path/to/logfile.log 2>&1

Replace admin with a WordPress username that has privileges to update WooCommerce product stats.

Viewing Cron Job Logs

To see the output of your cron jobs, you can redirect the output to a log file as shown in the examples above (> /path/to/logfile.log 2>&1).

To view the log:

cat /path/to/logfile.log

Or to see the log in real-time as it’s being written:

tail -f /path/to/logfile.log

Sending Email Notifications After Completion

You can configure your cron job to send an email when the import is complete:

0 2 * * * cd /path/to/your/wordpress && wp ssi 1 > /tmp/import-log.txt 2>&1 && mail -s "Import Completed" your@email.com < /tmp/import-log.txt

For a more detailed email with success/failure information:

0 2 * * * cd /path/to/your/wordpress && { wp ssi 1 && echo "Import completed successfully" || echo "Import failed with error code $?"; } | mail -s "Import Status" your@email.com

Troubleshooting

If your cron jobs aren’t running as expected:

  1. Check that the WordPress path is correct
  2. Ensure the user running the cron job has permission to execute WP-CLI
  3. Verify that WP-CLI is installed and accessible
  4. Check your log files for error messages
  5. Make sure your server’s time is set correctly

If you’re using a managed hosting provider, they may have their own cron job interface instead of the command-line crontab. Consult your hosting provider’s documentation for details.

Summary

You’ve learned how to schedule automated imports with Super Speedy Imports using crontab. You can now set up recurring imports that download files, process data, and update your WooCommerce store automatically. This automation can save you significant time and ensure your product data is always up to date.

Be the first to comment and we'll reply right away.

Leave a reply

×
1/1
Super Speedy Plugins
Logo