Welcome to Xeroom - Our website is currently being revamped [email protected]

How to Set Up Cron Jobs for Global Inventory & Product Synchs

This article discussed how Xeroom uses the cron job system to process inventory and product synchronizations. It looks at how to setup and optimize your cron job execution process.

 

How to Set Up Cron Jobs for Inventory & Product Synchs

Setting the Correct Batch Size

Xeroom creates batches in order to handle the Xero limitations on processing the no of inventory updates in one go.  Xero recommend 50-100 products are updated at once although we have found that 500 is a good number to start with for batch size and to only reduce it from there if you encounter problems since it is obviously more effecient to update in one larger batch rather than more smaller batches. Xeroom spawns cron jobs to process each batch and they execute at the rate of one/minute.  For manual “Synch Now” jobs the progress is also shown on the screen.  Log files are generated for each batch and numbered sequentially for each batch along with a time stamp.  To avoid lots of clutter only the last 50 log files are kept.

This is how the synch works:

  • Depending on the number of products to be sent and the batch size, Xeroom will calculate the number of batches that need to be sent.
  • Xeroom then spawns executable cron jobs that will send each batch to Xero at the rate of one/minute creating a log file for the updates.
  • After all the batches are sent, the process repeats depending on the user schedule selection: 5 minutes, hourly, daily.

 

Product Level Setting for Account Mapping

The accounts that product data maps into in Xero can be set at an overall level in the Xeroom settings General Tab or for better granularity at the product level can be set in the Product data tab where Xeroom adds a new tab for Xero account mapping settings which has fields for the Xero Tracking Category (if set), Sales Account, Cost of Goods Sold Account and Inventory Asset Account (for inventory values).  These can be bulk populated using a spreadsheet.

Note Brands here is an example of Xero Category Tracking which can be up to two categories which can be used by Xero to tag products with useful labels such as brand, branch, channel etc.

 

*For detailed info on how to bulk load these settings see separate help article in Help Portal.

 

Global Product Synchronization – Set Batch Size

The batching works exactly the same here as in the Global Inventory Synch.

 

Global Product Synchronization – Log Files 

As with the Global Inventory Synch the log filenames have been shortened and a batch number suffix added to each one for each run so it is easy to check that the synch is happening correctly and for all batches.

The Product Synch log file shows what the new values that have been changed to are for each product and also if unchanged will state that:

How Xeroom Runs Batch Jobs Using Cron

When you run the inventory or product synch or a bulk job in the WooCommerce Order dash you should see the job kicked off and get processed.  It won’t always be instant as it is due to the cron schedule and what other processes are running.  The bulk orders setting should be set to 4.  Here is a video to explain it. https://d.pr/v/yS4hEd  It should run after a minute or two and we have added a cancel button in case it remains suspended.  The cronjob scheduler plugin will tell you to disable the default wp-cron processer by putting this statement in wp-config and then to create a unix job in cpanel for your server  define(‘DISABLE_WP_CRON’, true);  However our experience is that some hosts will override or control this.   The WP crontrol plugin will enable you to see what is going on with your wp-cron system and show you all the events and schedules.  If it is not running then you need to speak to your host to determine why. You can also check the cron logs on your server https://cronitor.io/cron-reference/where-are-cron-logs-stored Note that cron is used by other parts of WordPress and detailed in the articles below.

1. Install the WP Crontrol plugin and update the attached file in your Xeroom plugin directory.

2. Set the batch send number to 4 in Xeroom settings

3. Run a Batch send and check if the cron job is spawned – If other cron jobs are running and no Xeroom job is spawned then there is something preventing it.  Try a few times and if it never appears let us know.  If it does appear then the problem is with the cron not running.

4. Check to see if WP-cron is disabled or not and if it is how cron jobs are run on your server.

 

Cron Job Troubleshooting

Xeroom enables you to check that the process is working since log files are created, which show under the Xeroom/log files menu item.  If these are not there and the batches are not running or running at weird intervals then check your cron system and if necessary, disable your WordPress cron process and enable a more robust and reliable server-based cron to run ideally every 5 minutes (beware of running them more frequently as large jobs that your system runs such as Updraft backups won’t complete in a min and can lead to starving the resources so do fully test).

For scheduled synchs running under cron the batches are processed at the same rate as the cron time interval, eg if cron is set to run every 5 mins and synch is hourly with say 3 batches then it will run the first batch each hour, then 5 mins later the next batch and so on.  For more visibility you can install a cron manager or scheduling plugin, there are lots and WP Control is a good one that shows both events and schedules.

For further info please see https://developer.wordpress.org/plugins/cron/ and https://www.wpeditorial.com/how-and-why-to-use-the-server-cron-instead-of-wp-cron/.

Q:  Can you send me the cron line to call the function: xeroom_sync_schedule?

A: https://wpspeedmatters.com/external-cron-jobs-in-wordpress/ Gives can find a detailed way to setup and achieve a 3rd party cron job on WordPress. Here is a short resume:

  • First, disable define('DISABLE_WP_CRON', true);
  • After that, go to the hosting dashboard cron job, create a new cron that executes every 1 or 2 minutes and add the URL wget -q -O - https://www.yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
 

The xeroom_sync_schedule is only available if something is in a queue to be synched with Xero. If not, the xeroom_sync_schedule cron will be removed. That’s why you should implement the 3rd party cron jobs as above.

 

 

Further Reading/Info on WordPress Cron Jobs

1. A very handy article https://themeisle.com/blog/disable-wp-cron/2. From the WordPress handbook https://developer.wordpress.org/plugins/cron/

What is WP-Cron?

WP-Cron is how WordPress handles scheduling time-based tasks in WordPress. Several WordPress core features, such as checking for updates and publishing scheduled post, utilize WP-Cron. The “Cron” part of the name comes from the cron time-based task scheduling system that is available on UNIX systems.WP-Cron works by checking, on every page load, a list of scheduled tasks to see what needs to be run. Any tasks due to run will be called during that page load. :WP-Cron does not run constantly as the system cron does; it is only triggered on page load. Scheduling errors could occur if you schedule a task for 2:00PM and no page loads occur until 5:00PM.

Why use WP-Cron?

· WordPress core and many plugins need a scheduling system to perform time-based tasks. However, many hosting services are shared and do not provide access to the system scheduler.· Using the WordPress API is a simpler method for setting scheduled tasks than going outside of WordPress to the system scheduler.

· With the system scheduler, if the time passes and the task did not run, it will not be re-attempted. With WP-Cron, all scheduled tasks are put into a queue and will run at the next opportunity (meaning the next page load). So while you can’t be 100% sure when your task will run, you can be 100% sure that it will run eventually.

 

Better Host Cron Job Management

Some of the better hosts provide WordPress cron management solutions eg Cloudways offer the below.  Ask your host if they offer this if you are not IT competent.

OTHER GUIDES

WHY XEROOM?

SIMPLE TO LEARN

EASY-TO-SETUP

USEFUL FEATURES

STABLE & ERROR FREE

FULLY AUTOMATED

GREAT COMPATIBILITY

AFFORDABLE PRICING

EXPERT SUPPORT

FAST LOW-COST INSTALL

EASY TO MIRROR

LOVED BY CUSTOMERS