Verification of Imported Orders
1. Quick Summary
- Check logs from Google Cloud Run services (mainly
bo-api,external-api,ops-api). - Identify
orderIdswith errors from the logs. - Validate the order status using
get_orders.py. - If necessary, fix dates/status using
update_orders.py. - Always perform a backup before any write operations (use
scripts/collection_backup).
2. Access (Google Cloud)
- Dev (testing):
https://console.cloud.google.com/welcome?invt=Ab6Akw&project=dingoo-dev - Production:
https://console.cloud.google.com/welcome?invt=Ab6Akw&project=dingoo-prod
Note: use an account with the appropriate permissions to view Cloud Run and logs.
3. Important API Services
bo-api— logs of orders added, updated, or failed.external-api— check external/integration errors.ops-api— operations API; useful for process-related errors.
4. Accessing Cloud Run and Viewing Logs
- Log in to Google Cloud (see links above).
- Search for Cloud Run (top search bar) or navigate via: menu → Cloud Run → Services.
- Open the bo-api service (or another relevant one).
- Go to Logs and click the filter/search icon on the right side.
- Adjust the time range:
- By default, it shows the “last hour.”
- For imported files (e.g., 06:00, 07:00, 08:00, 09:00, 09:30, 10:00), define a ±10-minute window around the time the file dropped in Slack (e.g.,
06:00–06:10) to make sure you capture the event. - If the file was uploaded a few minutes ago, click the arrow with a line (
-> |) to return to real-time view. - Look for the following events/strings:
Updated OrdersFailed OrdersOrders imported successfully- Expand the log entry to see the JSON body containing
orderIds and error messages.
5. Extracting orderIds from Logs
Method A — Manual (VSCode)
1. Expand the log entry until you see the list of orderIds.
2. Select and copy them (left-click).
3. Open a new json file in VSCode and paste.
4. If needed, remove text prefixes like Failed orders: before the {.
5. Format the file in VSCode with Alt + Shift + F (Windows) for readable JSON.
Method B — Using get_orders.py
- Copy only the orderIds and use the get_orders.py script to query the database and check the current order statuses.
- ATTENTION: always verify the businessId in the script before running it (see “Best Practices” section).
6. Setting Up the Environment (Clone Repository and Create Virtual Env)
- Clone the
new_backendrepository (or the one containing the scripts). - Navigate to the scripts folder:
- Create and activate a virtual environment (Windows):
(Linux / macOS:
source venv/bin/activate) - Install dependencies:
- Create a
.envfile following the example in the folder (contains DB connection credentials/strings).
7. Using get_orders.py
- Edit
get_orders.pyand insert theorderIdsfrom the logs into theorders_arrayvariable (or the respective field depending on the script format). - Run:
- Output: returns the current status of the orders (e.g.,
on_transit,packing, etc).
Note: for early morning files (e.g., 06:00, 07:00, 08:00), it’s useful to check both logs (6h and 7h) because an order might be updated but still appear with the previous date in one of the files.
8. Using update_orders.py (When Needed)
- In
update_orders.py, define: - The variable
resultwith the array oforderIds to be updated. -
The fields
current_delivery_dateandnew_delivery_datewith the correct dates. -
Run:
- It is highly recommended to perform a backup before executing this script.
9. Backup (scripts/collection_backup)
- Create a venv inside
scripts/collection_backup(same procedure as above). - Install requirements (
pip install -r requirements.txt) and create the.envfile. - To create a backup:
- To restore (only if absolutely necessary):
Warning: Using
restoremay impact operations and cause loss of data not included in the last backup. Use only when strictly necessary.
10. Best Practices and Warnings
- Always check the
businessIdbefore executing write operations. - Test scripts first in dev and confirm behavior before running in production.
- Always make a full backup before running
update_orders.py.
11. Quick Checklist (Step-by-Step)
- Open Cloud Run →
bo-api. - Filter time range (±10 min).
- Look for
Failed Orders/Updated Orders. - Copy
orderIdstoorders.jsonorget_orders.py. - Run
get_orders.pyand check statuses. - If necessary, create a backup (
python main.py backup). - Update with
update_orders.py. - Check logs and MongoDB after changes.
12. Useful Commands (Summary)
# Example: set up update_delivery_date environment (Windows)
cd new_backend/scripts/update_delivery_date
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
python get_orders.py
python update_orders.py
# Backup / restore
cd new_backend/scripts/collection_backup
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
python main.py backup
python main.py restore