Workflow Sync Service
TheWorkflowSyncService is responsible for orchestrating the synchronization of workflows from Zuora to the local database.
Overview
Responsibilities
- Validate customer credentials
- Fetch workflows from Zuora (paginated)
- Download JSON export for each workflow
- Save/update workflows in the database
- Delegate task extraction to the Workflow Model
- Delete obsolete workflows (cleanup)
Dependencies
ZuoraService for:
- OAuth authentication
- API calls to Zuora
- Download workflow JSON
Public Methods
syncCustomerWorkflows()
Synchronizes all workflows of a customer from the local database.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
$customer | Customer | Customer model instance |
Returns
Example
Workflow
-
Validate customer credentials:
- Verify
zuora_client_idis not empty - Verify
zuora_client_secretis not empty - Verify
zuora_base_urlis valid URL
- Verify
-
Iterate workflow pages:
- Fetch from Zuora (50 per page)
- Continue until no more pages
-
For each workflow:
- Call
syncWorkflowRecord() - Update statistics
- Call
-
Delete obsolete workflows:
- Call
deleteStaleWorkflows()
- Call
- Log result
Credential Validation
Private Methods
syncWorkflowRecord()
Synchronizes a single workflow record.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
$customer | Customer | Parent Customer instance |
$workflowData | array | Workflow data from Zuora |
Returns
Workflow
-
Get or create workflow:
-
Download JSON export:
-
Fill and save:
-
Synchronize tasks (delegates to Model):
downloadWorkflowJson()
Downloads the JSON export of a specific workflow.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
$customer | Customer | Customer instance |
$workflowId | string|int | Zuora ID of the workflow |
Returns
array: Complete JSON exportnull: If error (logs warning)
Workflow
deleteStaleWorkflows()
Deletes local workflows no longer present in Zuora.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
$customer | Customer | Customer instance |
$zuoraIds | array | Array of Zuora IDs present in Zuora |
Returns
int: Number of workflows deleted
Workflow
Constants
PAGE_SIZE
| Constant | Value | Description |
|---|---|---|
PAGE_SIZE | 50 | Number of workflows per API request |
Configuration Options
| Setting | Type | Default | Description |
|---|---|---|---|
| Page Size | Integer | 50 | Number of workflows fetched per page from Zuora API |
| Credential Validation | Boolean | Enabled | Validates customer credentials before sync starts |
| Stale Workflow Cleanup | Boolean | Enabled | Automatically removes workflows no longer in Zuora |
Error Handling
Handled Errors
| Error Type | Action | Retry |
|---|---|---|
| Invalid credentials | Terminate job immediately | No |
| Zuora API error | Add to errors[] array, continue with other workflows | No |
| Network timeout | Add to errors[] array, continue with other workflows | No |
| JSON parse error | Log warning, continue with other workflows | No |
| Missing workflow ID | Skip workflow, continue with others | No |
Error Logging
| Log Level | Condition | Context |
|---|---|---|
info | Successful sync completion | Customer ID, statistics |
warning | Individual workflow download failure | Customer ID, workflow ID, error message |
error | Sync process failure | Customer ID, error message |
Logging
Usage Examples
Synchronization from Job
Synchronization from Command
Manual Synchronization
Performance Considerations
Pagination
- Fetch 50 workflows per page
- Avoid timeout on large datasets
- Process sequentially
Eager Loading
When synchronizing multiple customers, use eager loading:Batch Processing
For many customers, use batch processing:Testing
Unit Test Example
See Also
- ZuoraService - Zuora API
- Workflow Model - Workflow Model
- Workflow Synchronization - Synchronization guide