Skip to content

Verification of Imported Orders


1. Quick Summary

  • Check logs from Google Cloud Run services (mainly bo-api, external-api, ops-api).
  • Identify orderIds with 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

  1. Log in to Google Cloud (see links above).
  2. Search for Cloud Run (top search bar) or navigate via: menu → Cloud RunServices.
  3. Open the bo-api service (or another relevant one).
  4. Go to Logs and click the filter/search icon on the right side.
  5. Adjust the time range:
  6. By default, it shows the “last hour.”
  7. 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.
  8. If the file was uploaded a few minutes ago, click the arrow with a line (-> |) to return to real-time view.
  9. Look for the following events/strings:
  10. Updated Orders
  11. Failed Orders
  12. Orders imported successfully
  13. 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)

  1. Clone the new_backend repository (or the one containing the scripts).
  2. Navigate to the scripts folder:
    cd new_backend/scripts/update_delivery_date
    
  3. Create and activate a virtual environment (Windows):
    python -m venv venv
    venv\Scripts\activate
    
    (Linux / macOS: source venv/bin/activate)
  4. Install dependencies:
    pip install -r requirements.txt
    
  5. Create a .env file following the example in the folder (contains DB connection credentials/strings).

7. Using get_orders.py

  • Edit get_orders.py and insert the orderIds from the logs into the orders_array variable (or the respective field depending on the script format).
  • Run:
    python get_orders.py
    
  • 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)

  1. In update_orders.py, define:
  2. The variable result with the array of orderIds to be updated.
  3. The fields current_delivery_date and new_delivery_date with the correct dates.

  4. Run:

    python update_orders.py
    

  5. It is highly recommended to perform a backup before executing this script.

9. Backup (scripts/collection_backup)

  1. Create a venv inside scripts/collection_backup (same procedure as above).
  2. Install requirements (pip install -r requirements.txt) and create the .env file.
  3. To create a backup:
    python main.py backup
    
  4. To restore (only if absolutely necessary):
    python main.py restore
    

    Warning: Using restore may 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 businessId before 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)

  1. Open Cloud Run → bo-api.
  2. Filter time range (±10 min).
  3. Look for Failed Orders / Updated Orders.
  4. Copy orderIds to orders.json or get_orders.py.
  5. Run get_orders.py and check statuses.
  6. If necessary, create a backup (python main.py backup).
  7. Update with update_orders.py.
  8. 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