-
Notifications
You must be signed in to change notification settings - Fork 10
Sync flow chart for Square 3.0 and above
Square version 3.0 replaces SkyVerge's Background Processing with Action Scheduler to handle Product Import, Manual Sync and Interval Sync. The details below explain the flow of all 3 processes.
Refer to https://github.com/woocommerce/woocommerce-square/pull/747 for more details.
A job is an object that contains one or more steps that needs to be executed sequentially to complete a job. When a job is created, the job is inserted in the wp_options
table. The name of a job is represented as wc_square_background_sync_job_<unique_id>
.
A collection of jobs that will be sequentially picked up by the job runner is known as a job queue.
A job runner is a process that picks up a job, runs all the steps within the job and then picks up the next job until all the jobs in a job queue are completed.
A step is a function that defines what the job does. A job contains a queue of step(s) that will be executed sequentially. A job status is set to complete
when all its steps are finished executing.
A step queue is a collection of steps (function names) that are meant to be executed sequentially to completion to finish a job.
This level describes the type of the jobs that can be created within Square.
- An Interval Polling job is created periodically by Square.
- A Product Import job is manually created when a user tries to Import Product from the Square's settings page.
- A Manual Sync job is manually created when a user tries to Sync products from the Square's settings page, or edits a Square synced product.
At this level, a job is created depending on the selected job. Creating a job inserts all the job details in the wp_options
table. At this point, the job is in queued
state.
As soon as a job is created, it is immediately followed by running as_enqueue_async_action( 'wc_square_job_runner' )
.
This command doesn't start processing the job right away. It only tells Action Scheduler to start processing the job whenever Action Scheduler is ready. It basically schedules the runner.
At this point, the callback to wc_square_job_runner
has started running. It fetches the first job from the job queue which is in the queued
state.
After fetching the job, it analyses the type of job and passes the job to the respective job handler. This is where the processing begins.
This step loads the necessary constants, etc.
The first step is fetched from the step queue.
The fetched step is executed to completion and the completed step is removed from the step queue.
Checks if there are more steps in the job yet to be completed. If so, control goes back to Level (C). The cycle repeats for the same job until all the steps within it are completed. Once all steps are completed, the job is marked as complete and the job queue is checked if more jobs are in a queued state ready to be processed.
Once all the jobs in the queued
state are marked as completed
, the runner stops.