How it works
When you start the sync task, shopMaster:Initialize the sync
The
start_sync_task() function in main.py:35 creates a database connection using your configured credentials and calls sync_data() to perform the first sync immediately.Schedule recurring syncs
Using the
schedule library, the application sets up a recurring task that runs start_sync_task() every 2 minutes (main.py:38).Monitor for changes
Each sync cycle queries the
ChangeLog table for INSERT and UPDATE operations (helper.py:308-311), processes the changes, and sends them to Digible’s API.The sync runs in a background thread (main.py:300-302) so it won’t block the UI, allowing you to continue working while syncs happen automatically.
Starting automatic sync
To start automatic sync:- Open shopMaster
- Navigate to the Home page
- Click the Start Sync task button
Stopping automatic sync
You can stop the scheduled sync at any time by clicking the Stop Sync task button. This callsschedule.clear() (main.py:56) to remove all scheduled jobs.
Background process
The sync scheduler runs in a daemon thread that:- Checks for pending scheduled tasks every 10 seconds (main.py:31-32)
- Runs independently of the main UI thread
- Automatically terminates when you close the application
What gets synced
Automatic sync processes:- INSERT operations: New products added to your local table
- UPDATE operations: Changes to existing product information
DELETE operations are not synced automatically. The sync process only handles INSERT and UPDATE changes from the ChangeLog table.
Error handling
If the sync encounters issues:- Expired token: The function returns
Falseand displays “User Session expired please reconfigure” (main.py:48) - Network issues: The
is_connected()check (helper.py:295) prevents sync attempts when offline - API errors: Exceptions are caught and logged, but the scheduler continues running
sync_data() implementation.