Qeasy Cloud
Get Started

Scheduled Data Cleanup Strategy: A Practical Guide for SQL Server and Jushuitan Integration Scenarios

· 卢剑航· Integration Solutions· 25 views· 4 min read

What This Strategy Solves

In one retail client's supply chain integration project, we continuously sync sales outbound orders and after-sales orders from Jushuitan into SQL Server. After six months, the historical document tables in SQL Server and the run logs on the integration platform swelled rapidly, queries slowed down, and the backup window was squeezed. Manual cleanup is neither reliable nor auditable. That is when a scheduled data cleanup strategy is needed — automatically removing expired data by a time window, so that both sides stay lean.

Data Flow and Field Mapping

The logic of scheduled cleanup is not complex, but the parameters must align.

Call chain: Source (preview of records to delete) → Middle layer (Qeasy platform DeleteStrategyData) → Target (execute deletion)

FieldSource (QUERY)Target (EXECUTE)Description
target_1Sales outbound (object, required)target_1 (object)Target object to clean; can define target_2, target_3
strategy_id—strategy_id (string, required)ID of the specific strategy to clean
begin_at—Long date (required)Start time, usually a very early date as the lower bound
end_at—Long date (required)End time, typically DATE_SUB(now(), INTERVAL 60 DAY)
datetimedatetime (auto)—Returned timestamp
paramsparams (auto)—Returned parameter echo

The source effect=QUERY is used to preview "which data will be deleted", while the target effect=EXECUTE actually performs the deletion. Both calls share the same DeleteStrategyData interface but have different semantics — this is the most confusing part.

How to Configure in Qeasy

Platform access: Create a WebAPI connection in Qeasy, select the DeleteStrategyData interface, with Method fixed as POST.

Source node (QUERY):

  • crontab: 3 12 * * * (preview at 12:03 every day for manual review)
  • autoFillResponse: true, to directly get datetime and params echo
  • Request body only contains target_1, no need for begin_at/end_at

Target node (EXECUTE):

  • crontab: 1 1 1 1 1 (only triggered at 01:01 on the first Monday of each month, executed cautiously)
  • Request body filled with target_1, strategy_id, begin_at (a remote start date like 2000-01-01), end_at (use a function expression to calculate 60 days ago)
  • idCheck: true, to prevent accidental deletion

In engineering practice, we usually maintain begin_at/end_at in Qeasy's centralized code mapping table, so that when the business adjusts the retention period, only one place needs to be modified, avoiding scattered configurations across multiple strategies.

Implementation Steps

Phase 1: Verify boundaries (full trigger) Manually trigger a QUERY node in the test environment to confirm that the number of records hit in the returned params matches expectations. Do not skip this step and go directly to EXECUTE — this is a typical pitfall.

Phase 2: Gradual rollout (incremental starting point) Change end_at to a conservative value (e.g., 180 days ago), first clean up historical data that "will clearly no longer be queried", and observe one or two scheduling cycles.

Phase 3: Steady-state operation (scheduling frequency) The source previews once a day at 12:03, and the target executes during off-peak hours (early morning or at the beginning of the month); the frequency should not be too high. Qeasy's Cron supports both five-segment and six-segment formats, which is more flexible than many schedulers.

Phase 4: Audit and alerting Write the number of records deleted each time to a monitoring channel through Qeasy's callback. If the number is abnormal (e.g., tens of thousands of records suddenly cleaned), an alert is triggered immediately.

Lessons Learned

  1. Using QUERY as EXECUTE: The two nodes share the same API name, differing only in effect. In one actual project, a new colleague directly used the QUERY configuration as EXECUTE, resulting in the "cleanup" not taking effect at all, and they thought it was a platform bug. The safe approach is to distinguish them with different naming suffixes.
  2. end_at written as a fixed value: Using a dead value like 2024-01-01, the strategy "stalls" after running for a year. Use platform-supported date functions for dynamic calculation, such as DATE_SUB(now(), INTERVAL 60 DAY).
  3. One-size-fits-all retention period: 60 days is appropriate for sales outbound orders, but too short for after-sales orders (disputes may need to be traced for 1 year). It is recommended to stage by business object: core documents are retained longer, logs shorter.
  4. No QUERY preview before deletion: If end_at is written incorrectly, the entire table may be emptied. We later stipulated: before any cleanup strategy goes live, there must be a recent successful QUERY screenshot archived.
  5. Cron timezone not aligned: The Qeasy platform's default timezone is inconsistent with the business database, causing "execution at 1 AM" to actually become 9 AM. Confirm the platform timezone before configuration, or convert it in the expression.

Applicable and Non-Applicable Scenarios

Applicable: Run logs, historical documents, temporary intermediate tables, reconciliation difference tables and other "append-only" data; data with a clear compliance retention period (60/90/180 days); cleanup actions that need to be auditable and replayable.

Not applicable: Core master data that needs long-term archiving (materials, customers); orders under dispute; "bare deletion" scenarios without QUERY preview; and fine-grained window cleanup with a frequency requirement lower than 1 day (the platform Cron is not suitable for minute-level scheduling).

Original content. Please credit the source when reposting: https://www.qeasy.cloud/insights/solutions/strat-sql-server-jushuitan-3417-n2dc53f81-bf6f0ae9

Comments