Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/main.py +84 -13
- api/odoo_relational.py +37 -8
- api/routes_connectors.py +14 -1
- api/test_odoo_rank_refresh.py +90 -10
- platform/modules/aged_stock.py +14 -1
- platform/modules/opportunity_finder.py +11 -3
- platform/modules/ranking_diagnostic.py +13 -3
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
- web/src/connectors/ConnectorsPage.tsx +44 -2
RELEASES.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": []
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "4758e6c77",
|
| 3 |
"releases": []
|
| 4 |
}
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
4758e6c77
|
api/main.py
CHANGED
|
@@ -2557,6 +2557,28 @@ def _resync_publication_held(sync_report, tenant=None):
|
|
| 2557 |
return True
|
| 2558 |
|
| 2559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2560 |
def _smallest_first(ds, keys):
|
| 2561 |
"""`keys` ordered by their Odoo row count, so a small table answers before a large backfill."""
|
| 2562 |
def size(key):
|
|
@@ -2679,14 +2701,14 @@ def _resync_memory_write(pass_at, full_rebuild_at, fingerprints, pulls=None):
|
|
| 2679 |
"the next restart rebuilds in full")
|
| 2680 |
|
| 2681 |
|
| 2682 |
-
def _resync_slot_pass_write(at):
|
| 2683 |
-
"""H73: persist
|
| 2684 |
try:
|
| 2685 |
import odoo_relational as _rel_slot
|
| 2686 |
from harness import runtime as _runtime_slot
|
| 2687 |
-
_rel_slot.record_slot_pass(_runtime_slot.get_runtime(_resync_tenant()[0]), at)
|
| 2688 |
except Exception as e: # noqa: BLE001
|
| 2689 |
-
print(f"[aios-api] store resync slot stamp not saved ({type(e).__name__}); "
|
| 2690 |
"a restart before the next slot may run this one again")
|
| 2691 |
|
| 2692 |
|
|
@@ -2849,6 +2871,15 @@ def _store_resync_loop():
|
|
| 2849 |
# H73: the start of the last daily-slot pass, and whether the boot restore already ran.
|
| 2850 |
last_slot_pass_at = _memory.get("slotPassAt")
|
| 2851 |
slot_restored = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2852 |
while True:
|
| 2853 |
# ⭐⭐ WAVE 32 · OWNER ITEM 11 / R11 — THE TENANT'S OWN CADENCE, NOT A HARDCODED 1800.
|
| 2854 |
#
|
|
@@ -2927,8 +2958,9 @@ def _store_resync_loop():
|
|
| 2927 |
# full pass too, so passes start a day apart however long the pass ran (a daily pass
|
| 2928 |
# that also refreshes every Amazon table can run an hour, and a wait counted from its
|
| 2929 |
# END drifted later every day and past the 26-hour stale line).
|
| 2930 |
-
_woken = bool(connector_sync.sync_wake_event().wait(
|
| 2931 |
-
max(0.0, _every - (_t.time() - last_full_pass_at))
|
|
|
|
| 2932 |
connector_sync.sync_wake_event().clear()
|
| 2933 |
_slot_due = False
|
| 2934 |
if _slot is not None:
|
|
@@ -2938,12 +2970,23 @@ def _store_resync_loop():
|
|
| 2938 |
if passes or slot_restored:
|
| 2939 |
# Sleep to one second past the next slot; Sync now still interrupts the wait.
|
| 2940 |
_slot_now = _t.time()
|
| 2941 |
-
_woken = bool(connector_sync.sync_wake_event().wait(
|
| 2942 |
0.0 if _rel_slot.slot_due(_slot_now, _slot, last_slot_pass_at)
|
| 2943 |
-
else max(0.0, _rel_slot.slot_after(_slot_now, _slot) + 1.0 - _slot_now)
|
|
|
|
| 2944 |
connector_sync.sync_wake_event().clear()
|
| 2945 |
_slot_now = _t.time()
|
| 2946 |
_slot_due = _rel_slot.slot_due(_slot_now, _slot, last_slot_pass_at)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2947 |
# The scheduled pass after the one this cycle may run.
|
| 2948 |
RESYNC_STATE["nextPassAt"] = _rel_slot.slot_iso(_rel_slot.slot_after(_slot_now, _slot))
|
| 2949 |
else:
|
|
@@ -2977,7 +3020,11 @@ def _store_resync_loop():
|
|
| 2977 |
_odoo_requested = True
|
| 2978 |
else:
|
| 2979 |
_odoo_requested = None
|
| 2980 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2981 |
# H73: outside the slot no Odoo call is made. Serve the stored mirror, drain the desk.
|
| 2982 |
_desk = {}
|
| 2983 |
if _run_sync_requests(_desk):
|
|
@@ -2993,14 +3040,20 @@ def _store_resync_loop():
|
|
| 2993 |
f"runs at {RESYNC_STATE['nextPassAt']} ({_slot['at']} {_slot['tz']})")
|
| 2994 |
continue
|
| 2995 |
passes += 1
|
| 2996 |
-
|
| 2997 |
-
if
|
| 2998 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2999 |
last_slot_pass_at = last_full_pass_at
|
| 3000 |
-
(
|
| 3001 |
if _odoo_requested is None:
|
| 3002 |
_odoo_requested = _run_sync_requests()
|
| 3003 |
_warm_generation = _sheet_warm_generation()
|
|
|
|
| 3004 |
try:
|
| 3005 |
selected_entities = _configured_mirror_entities(_cad["tenant"])
|
| 3006 |
sync_report, delete_report, _err = _resync_mirror_pass(_manual, passes, selected_entities)
|
|
@@ -3039,6 +3092,22 @@ def _store_resync_loop():
|
|
| 3039 |
if _publication_held:
|
| 3040 |
print("[aios-api] store resync: publication held; no vendor pulls or relational rebuild; "
|
| 3041 |
"the next admitted pass resumes the unfinished Odoo cohort")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3042 |
continue
|
| 3043 |
if _boot_catch_up and not _odoo_requested:
|
| 3044 |
# Restore only: the saved Amazon mirror and its read-through registry, no vendor call.
|
|
@@ -3228,6 +3297,8 @@ def _store_resync_loop():
|
|
| 3228 |
last_source_fingerprints, None if _pass_good else dict(_pulls))
|
| 3229 |
_sheet_warm_after_pass(_cad["tenant"], _pass_good, _warm_generation,
|
| 3230 |
_reason is not None or bool(_meta_state.get("applied")))
|
|
|
|
|
|
|
| 3231 |
|
| 3232 |
|
| 3233 |
def _boot_app_migrations(why):
|
|
|
|
| 2557 |
return True
|
| 2558 |
|
| 2559 |
|
| 2560 |
+
def _odoo_backfill_checkpoints(tenant=None):
|
| 2561 |
+
"""The held Odoo candidate's unfinished `_sync_state` rows; () without a candidate, None if unreadable."""
|
| 2562 |
+
try:
|
| 2563 |
+
from harness import datastore, mirror_store, runtime
|
| 2564 |
+
rt = runtime.get_runtime(tenant) if tenant else datastore._resident_odoo_runtime()
|
| 2565 |
+
if rt is None:
|
| 2566 |
+
return ()
|
| 2567 |
+
store = mirror_store.for_connector("odoo")
|
| 2568 |
+
path = Path(rt.datastore_path).with_suffix(".odoo.candidate.duckdb")
|
| 2569 |
+
with store.lock:
|
| 2570 |
+
if not path.exists():
|
| 2571 |
+
return ()
|
| 2572 |
+
con = datastore.apply_limits(datastore.duckdb.connect(str(path)))
|
| 2573 |
+
try:
|
| 2574 |
+
# entity, phase, last_id, cursor_wd, rows: every bounded page moves one of them.
|
| 2575 |
+
return tuple(row[:5] for row in store._state_rows(con) if row[1] not in {"live", "done"})
|
| 2576 |
+
finally:
|
| 2577 |
+
con.close()
|
| 2578 |
+
except Exception: # noqa: BLE001
|
| 2579 |
+
return None
|
| 2580 |
+
|
| 2581 |
+
|
| 2582 |
def _smallest_first(ds, keys):
|
| 2583 |
"""`keys` ordered by their Odoo row count, so a small table answers before a large backfill."""
|
| 2584 |
def size(key):
|
|
|
|
| 2701 |
"the next restart rebuilds in full")
|
| 2702 |
|
| 2703 |
|
| 2704 |
+
def _resync_slot_pass_write(at, field="slotPassAt"):
|
| 2705 |
+
"""H73: persist one slot stamp, by default a pass's start. Best effort: a lost write repeats it once."""
|
| 2706 |
try:
|
| 2707 |
import odoo_relational as _rel_slot
|
| 2708 |
from harness import runtime as _runtime_slot
|
| 2709 |
+
_rel_slot.record_slot_pass(_runtime_slot.get_runtime(_resync_tenant()[0]), at, field)
|
| 2710 |
except Exception as e: # noqa: BLE001
|
| 2711 |
+
print(f"[aios-api] store resync slot stamp {field} not saved ({type(e).__name__}); "
|
| 2712 |
"a restart before the next slot may run this one again")
|
| 2713 |
|
| 2714 |
|
|
|
|
| 2871 |
# H73: the start of the last daily-slot pass, and whether the boot restore already ran.
|
| 2872 |
last_slot_pass_at = _memory.get("slotPassAt")
|
| 2873 |
slot_restored = False
|
| 2874 |
+
# H2: the first slot cycle checks once whether a restart killed the newest slot's pass.
|
| 2875 |
+
slot_resume_checked = False
|
| 2876 |
+
_slot_write = globals().get("_resync_slot_pass_write") or (lambda *_a, **_k: None)
|
| 2877 |
+
# H1: a held Odoo backfill that moved queues a bounded Odoo-only pass, at most 24 per slot day.
|
| 2878 |
+
_backfill_read = globals().get("_odoo_backfill_checkpoints")
|
| 2879 |
+
backfill_next_at = None
|
| 2880 |
+
backfill_continuations = 0
|
| 2881 |
+
backfill_spacing_seconds = 60.0
|
| 2882 |
+
backfill_cap = 24
|
| 2883 |
while True:
|
| 2884 |
# ⭐⭐ WAVE 32 · OWNER ITEM 11 / R11 — THE TENANT'S OWN CADENCE, NOT A HARDCODED 1800.
|
| 2885 |
#
|
|
|
|
| 2958 |
# full pass too, so passes start a day apart however long the pass ran (a daily pass
|
| 2959 |
# that also refreshes every Amazon table can run an hour, and a wait counted from its
|
| 2960 |
# END drifted later every day and past the 26-hour stale line).
|
| 2961 |
+
_woken = bool(connector_sync.sync_wake_event().wait(min(
|
| 2962 |
+
max(0.0, _every - (_t.time() - last_full_pass_at)),
|
| 2963 |
+
float("inf") if backfill_next_at is None else max(0.0, backfill_next_at - _t.time()))))
|
| 2964 |
connector_sync.sync_wake_event().clear()
|
| 2965 |
_slot_due = False
|
| 2966 |
if _slot is not None:
|
|
|
|
| 2970 |
if passes or slot_restored:
|
| 2971 |
# Sleep to one second past the next slot; Sync now still interrupts the wait.
|
| 2972 |
_slot_now = _t.time()
|
| 2973 |
+
_woken = bool(connector_sync.sync_wake_event().wait(min(
|
| 2974 |
0.0 if _rel_slot.slot_due(_slot_now, _slot, last_slot_pass_at)
|
| 2975 |
+
else max(0.0, _rel_slot.slot_after(_slot_now, _slot) + 1.0 - _slot_now),
|
| 2976 |
+
float("inf") if backfill_next_at is None else max(0.0, backfill_next_at - _slot_now))))
|
| 2977 |
connector_sync.sync_wake_event().clear()
|
| 2978 |
_slot_now = _t.time()
|
| 2979 |
_slot_due = _rel_slot.slot_due(_slot_now, _slot, last_slot_pass_at)
|
| 2980 |
+
if not slot_resume_checked:
|
| 2981 |
+
slot_resume_checked = True
|
| 2982 |
+
# H2: a claim with no end is a pass a restart killed. Resume it once per slot.
|
| 2983 |
+
_killed = _rel_slot.slot_pass_killed(_slot_now, _slot, _memory)
|
| 2984 |
+
if _killed is not None and not _slot_due:
|
| 2985 |
+
_slot_due = True
|
| 2986 |
+
_slot_write(_killed, "slotResumedFor")
|
| 2987 |
+
print(f"[aios-api] store resync: the {_slot['at']} {_slot['tz']} slot pass "
|
| 2988 |
+
f"started at {_rel_slot.slot_iso(_memory['slotPassAt'])} never finished; "
|
| 2989 |
+
f"running it once now")
|
| 2990 |
# The scheduled pass after the one this cycle may run.
|
| 2991 |
RESYNC_STATE["nextPassAt"] = _rel_slot.slot_iso(_rel_slot.slot_after(_slot_now, _slot))
|
| 2992 |
else:
|
|
|
|
| 3020 |
_odoo_requested = True
|
| 3021 |
else:
|
| 3022 |
_odoo_requested = None
|
| 3023 |
+
# H1: a queued backfill pass that is due, unless the slot, the cadence or a Sync now runs.
|
| 3024 |
+
_continuation = (backfill_next_at is not None and _t.time() >= backfill_next_at - 1.0
|
| 3025 |
+
and _odoo_requested is None and not _slot_due
|
| 3026 |
+
and (_slot is not None or _t.time() - last_full_pass_at < _every))
|
| 3027 |
+
if _slot is not None and not _slot_due and _odoo_requested is None and not _continuation:
|
| 3028 |
# H73: outside the slot no Odoo call is made. Serve the stored mirror, drain the desk.
|
| 3029 |
_desk = {}
|
| 3030 |
if _run_sync_requests(_desk):
|
|
|
|
| 3040 |
f"runs at {RESYNC_STATE['nextPassAt']} ({_slot['at']} {_slot['tz']})")
|
| 3041 |
continue
|
| 3042 |
passes += 1
|
| 3043 |
+
backfill_next_at = None
|
| 3044 |
+
if not _continuation:
|
| 3045 |
+
# A continuation keeps the cadence, the slot stamp and the day's continuation count.
|
| 3046 |
+
last_full_pass_at = _t.time()
|
| 3047 |
+
backfill_continuations = 0
|
| 3048 |
+
_slot_claimed = _slot is not None and _slot_due
|
| 3049 |
+
if _slot_claimed:
|
| 3050 |
+
# H73: stamp the slot BEFORE any Odoo read. H2: `slotDoneAt` marks its end, any outcome.
|
| 3051 |
last_slot_pass_at = last_full_pass_at
|
| 3052 |
+
_slot_write(last_full_pass_at)
|
| 3053 |
if _odoo_requested is None:
|
| 3054 |
_odoo_requested = _run_sync_requests()
|
| 3055 |
_warm_generation = _sheet_warm_generation()
|
| 3056 |
+
_backfill_before = _backfill_read(_cad["tenant"]) if _backfill_read else None
|
| 3057 |
try:
|
| 3058 |
selected_entities = _configured_mirror_entities(_cad["tenant"])
|
| 3059 |
sync_report, delete_report, _err = _resync_mirror_pass(_manual, passes, selected_entities)
|
|
|
|
| 3092 |
if _publication_held:
|
| 3093 |
print("[aios-api] store resync: publication held; no vendor pulls or relational rebuild; "
|
| 3094 |
"the next admitted pass resumes the unfinished Odoo cohort")
|
| 3095 |
+
if _slot_claimed:
|
| 3096 |
+
_slot_write(_t.time(), "slotDoneAt")
|
| 3097 |
+
# H1: progress is a changed unfinished checkpoint in the candidate's `_sync_state`.
|
| 3098 |
+
_backfill_after = _backfill_read(_cad["tenant"]) if _backfill_read else None
|
| 3099 |
+
_moved = ([row for row in _backfill_after if row not in _backfill_before]
|
| 3100 |
+
if _err is None and _backfill_after and _backfill_before is not None else [])
|
| 3101 |
+
if _moved and backfill_continuations >= backfill_cap:
|
| 3102 |
+
print(f"[aios-api] odoo backfill stops for today: {backfill_cap} bounded passes ran; "
|
| 3103 |
+
f"the next slot pass or Sync now resumes it")
|
| 3104 |
+
elif _moved:
|
| 3105 |
+
backfill_continuations += 1
|
| 3106 |
+
backfill_next_at = _t.time() + backfill_spacing_seconds
|
| 3107 |
+
_row = max(_moved, key=lambda row: row[4] or 0)
|
| 3108 |
+
print(f"[aios-api] odoo backfill continues: {str(_row[0]).split('.', 1)[0]} at "
|
| 3109 |
+
f"{_row[4] or 0:,} rows; next bounded pass queued "
|
| 3110 |
+
f"({backfill_continuations} of {backfill_cap} today)")
|
| 3111 |
continue
|
| 3112 |
if _boot_catch_up and not _odoo_requested:
|
| 3113 |
# Restore only: the saved Amazon mirror and its read-through registry, no vendor call.
|
|
|
|
| 3297 |
last_source_fingerprints, None if _pass_good else dict(_pulls))
|
| 3298 |
_sheet_warm_after_pass(_cad["tenant"], _pass_good, _warm_generation,
|
| 3299 |
_reason is not None or bool(_meta_state.get("applied")))
|
| 3300 |
+
if _slot_claimed:
|
| 3301 |
+
_slot_write(_t.time(), "slotDoneAt")
|
| 3302 |
|
| 3303 |
|
| 3304 |
def _boot_app_migrations(why):
|
api/odoo_relational.py
CHANGED
|
@@ -5605,6 +5605,26 @@ def slot_due(now, slot, last_pass_at):
|
|
| 5605 |
return last_pass_at is None or float(last_pass_at) < slot_before(now, slot)
|
| 5606 |
|
| 5607 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5608 |
def slot_iso(epoch):
|
| 5609 |
"""An epoch as ISO UTC with a `Z`, the shape `nextSyncAt` speaks."""
|
| 5610 |
# isoformat, not strftime: strftime reads the `time` module, which the loop's tests replace.
|
|
@@ -5735,7 +5755,7 @@ def decode_fingerprints(stored):
|
|
| 5735 |
def read_resync_memory(rt):
|
| 5736 |
"""What the last container's resync loop knew, or empty values. Never raises."""
|
| 5737 |
empty = {"passAt": None, "fullRebuildAt": None, "fingerprints": None, "lastGoodSyncAt": None,
|
| 5738 |
-
"pulls": None, "slotPassAt": None}
|
| 5739 |
try:
|
| 5740 |
cur = rt.get(CONFIG_KEY) if rt is not None else None
|
| 5741 |
except Exception: # noqa: BLE001
|
|
@@ -5750,7 +5770,9 @@ def read_resync_memory(rt):
|
|
| 5750 |
"lastGoodSyncAt": _memory_epoch(cur.get("lastGoodSyncAt")),
|
| 5751 |
"pulls": ({str(k): _memory_epoch(v) for k, v in pulls.items()}
|
| 5752 |
if isinstance(pulls, dict) and pulls else None),
|
| 5753 |
-
"slotPassAt": _memory_epoch(memory.get("slotPassAt"))
|
|
|
|
|
|
|
| 5754 |
|
| 5755 |
|
| 5756 |
def record_resync_memory(rt, *, pass_at, full_rebuild_at, fingerprints, pulls=None):
|
|
@@ -5767,10 +5789,11 @@ def record_resync_memory(rt, *, pass_at, full_rebuild_at, fingerprints, pulls=No
|
|
| 5767 |
|
| 5768 |
def _up(cur):
|
| 5769 |
cur = dict(cur) if isinstance(cur, dict) else {}
|
| 5770 |
-
# H73: the slot
|
| 5771 |
prior = cur.get(RESYNC_MEMORY_FIELD)
|
| 5772 |
-
|
| 5773 |
-
|
|
|
|
| 5774 |
cur[RESYNC_MEMORY_FIELD] = memory
|
| 5775 |
return cur
|
| 5776 |
|
|
@@ -5778,8 +5801,14 @@ def record_resync_memory(rt, *, pass_at, full_rebuild_at, fingerprints, pulls=No
|
|
| 5778 |
return memory
|
| 5779 |
|
| 5780 |
|
| 5781 |
-
|
| 5782 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5783 |
stamp = (_dt.datetime.fromtimestamp(float(at), _dt.timezone.utc).isoformat()
|
| 5784 |
if isinstance(at, (int, float)) else str(at))
|
| 5785 |
|
|
@@ -5787,7 +5816,7 @@ def record_slot_pass(rt, at):
|
|
| 5787 |
cur = dict(cur) if isinstance(cur, dict) else {}
|
| 5788 |
memory = cur.get(RESYNC_MEMORY_FIELD)
|
| 5789 |
memory = dict(memory) if isinstance(memory, dict) else {}
|
| 5790 |
-
memory[
|
| 5791 |
cur[RESYNC_MEMORY_FIELD] = memory
|
| 5792 |
return cur
|
| 5793 |
|
|
|
|
| 5605 |
return last_pass_at is None or float(last_pass_at) < slot_before(now, slot)
|
| 5606 |
|
| 5607 |
|
| 5608 |
+
def slot_pass_killed(now, slot, memory):
|
| 5609 |
+
"""The latest slot's epoch when its claimed pass never ended and was not resumed, else None.
|
| 5610 |
+
|
| 5611 |
+
A `passAt` at or after the claim also ends it, which covers memory from older code.
|
| 5612 |
+
"""
|
| 5613 |
+
memory = memory if isinstance(memory, dict) else {}
|
| 5614 |
+
claim = memory.get("slotPassAt")
|
| 5615 |
+
newest = slot_before(now, slot)
|
| 5616 |
+
if claim is None or float(claim) < newest:
|
| 5617 |
+
return None
|
| 5618 |
+
ends = [float(at) for at in (memory.get("slotDoneAt"), memory.get("passAt")) if at is not None]
|
| 5619 |
+
if ends and max(ends) >= float(claim):
|
| 5620 |
+
return None
|
| 5621 |
+
resumed = memory.get("slotResumedFor")
|
| 5622 |
+
# Storm guard: a slot pass killed again after its one resume waits for the next slot.
|
| 5623 |
+
if resumed is not None and float(resumed) >= newest:
|
| 5624 |
+
return None
|
| 5625 |
+
return newest
|
| 5626 |
+
|
| 5627 |
+
|
| 5628 |
def slot_iso(epoch):
|
| 5629 |
"""An epoch as ISO UTC with a `Z`, the shape `nextSyncAt` speaks."""
|
| 5630 |
# isoformat, not strftime: strftime reads the `time` module, which the loop's tests replace.
|
|
|
|
| 5755 |
def read_resync_memory(rt):
|
| 5756 |
"""What the last container's resync loop knew, or empty values. Never raises."""
|
| 5757 |
empty = {"passAt": None, "fullRebuildAt": None, "fingerprints": None, "lastGoodSyncAt": None,
|
| 5758 |
+
"pulls": None, "slotPassAt": None, "slotDoneAt": None, "slotResumedFor": None}
|
| 5759 |
try:
|
| 5760 |
cur = rt.get(CONFIG_KEY) if rt is not None else None
|
| 5761 |
except Exception: # noqa: BLE001
|
|
|
|
| 5770 |
"lastGoodSyncAt": _memory_epoch(cur.get("lastGoodSyncAt")),
|
| 5771 |
"pulls": ({str(k): _memory_epoch(v) for k, v in pulls.items()}
|
| 5772 |
if isinstance(pulls, dict) and pulls else None),
|
| 5773 |
+
"slotPassAt": _memory_epoch(memory.get("slotPassAt")),
|
| 5774 |
+
"slotDoneAt": _memory_epoch(memory.get("slotDoneAt")),
|
| 5775 |
+
"slotResumedFor": _memory_epoch(memory.get("slotResumedFor"))}
|
| 5776 |
|
| 5777 |
|
| 5778 |
def record_resync_memory(rt, *, pass_at, full_rebuild_at, fingerprints, pulls=None):
|
|
|
|
| 5789 |
|
| 5790 |
def _up(cur):
|
| 5791 |
cur = dict(cur) if isinstance(cur, dict) else {}
|
| 5792 |
+
# H73: the slot stamps are written by `record_slot_pass` alone, so a whole-dict write keeps them.
|
| 5793 |
prior = cur.get(RESYNC_MEMORY_FIELD)
|
| 5794 |
+
for field in SLOT_MEMORY_FIELDS:
|
| 5795 |
+
if isinstance(prior, dict) and prior.get(field):
|
| 5796 |
+
memory[field] = prior[field]
|
| 5797 |
cur[RESYNC_MEMORY_FIELD] = memory
|
| 5798 |
return cur
|
| 5799 |
|
|
|
|
| 5801 |
return memory
|
| 5802 |
|
| 5803 |
|
| 5804 |
+
#: The slot stamps: a pass's start, its end (any outcome), and the slot whose killed pass was resumed.
|
| 5805 |
+
SLOT_MEMORY_FIELDS = ("slotPassAt", "slotDoneAt", "slotResumedFor")
|
| 5806 |
+
|
| 5807 |
+
|
| 5808 |
+
def record_slot_pass(rt, at, field="slotPassAt"):
|
| 5809 |
+
"""Merge one slot stamp (ISO) into the resync memory, by default the start of the last slot pass."""
|
| 5810 |
+
if field not in SLOT_MEMORY_FIELDS:
|
| 5811 |
+
raise ValueError(f"not a slot stamp: {field}")
|
| 5812 |
stamp = (_dt.datetime.fromtimestamp(float(at), _dt.timezone.utc).isoformat()
|
| 5813 |
if isinstance(at, (int, float)) else str(at))
|
| 5814 |
|
|
|
|
| 5816 |
cur = dict(cur) if isinstance(cur, dict) else {}
|
| 5817 |
memory = cur.get(RESYNC_MEMORY_FIELD)
|
| 5818 |
memory = dict(memory) if isinstance(memory, dict) else {}
|
| 5819 |
+
memory[field] = stamp
|
| 5820 |
cur[RESYNC_MEMORY_FIELD] = memory
|
| 5821 |
return cur
|
| 5822 |
|
api/routes_connectors.py
CHANGED
|
@@ -3007,10 +3007,23 @@ def connector_sync_status(connector_key: str, connection_id: str = None,
|
|
| 3007 |
else:
|
| 3008 |
completed, known = _daily_completed_sync(rt, connector_key)
|
| 3009 |
answer.update(schedule="daily", lastCompletedAt=completed, lastSyncAt=completed,
|
| 3010 |
-
lastCompletedKnown=known, canSync=bool(session.admin)
|
|
|
|
| 3011 |
return _safe_connector_status(connector_key, answer)
|
| 3012 |
|
| 3013 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3014 |
@router.post("/connectors/{connector_key}/sync/now")
|
| 3015 |
def connector_sync_now(connector_key: str, connection_id: str = None,
|
| 3016 |
session: Session = Depends(require_session)):
|
|
|
|
| 3007 |
else:
|
| 3008 |
completed, known = _daily_completed_sync(rt, connector_key)
|
| 3009 |
answer.update(schedule="daily", lastCompletedAt=completed, lastSyncAt=completed,
|
| 3010 |
+
lastCompletedKnown=known, canSync=bool(session.admin),
|
| 3011 |
+
**_daily_sync_staleness(completed))
|
| 3012 |
return _safe_connector_status(connector_key, answer)
|
| 3013 |
|
| 3014 |
|
| 3015 |
+
def _daily_sync_staleness(completed, now=None):
|
| 3016 |
+
"""Odoo's stale rule for a daily cadence: stale only past cadence plus grace after a completed sync."""
|
| 3017 |
+
import odoo_relational as rel
|
| 3018 |
+
allowed = rel.SYNC_PRESETS["daily"] + rel.STALE_GRACE_SECONDS
|
| 3019 |
+
stamp = _sync_stamp(completed)
|
| 3020 |
+
if stamp is None:
|
| 3021 |
+
return {"stale": False, "staleAfterSeconds": allowed}
|
| 3022 |
+
now = now or datetime.now(timezone.utc)
|
| 3023 |
+
age = (now - datetime.fromisoformat(stamp)).total_seconds()
|
| 3024 |
+
return {"stale": age > allowed, "staleAfterSeconds": allowed}
|
| 3025 |
+
|
| 3026 |
+
|
| 3027 |
@router.post("/connectors/{connector_key}/sync/now")
|
| 3028 |
def connector_sync_now(connector_key: str, connection_id: str = None,
|
| 3029 |
session: Session = Depends(require_session)):
|
api/test_odoo_rank_refresh.py
CHANGED
|
@@ -198,7 +198,7 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 198 |
# every pass would ask for a zero wait.
|
| 199 |
clock = SimpleNamespace(sleep=sleep, time=lambda: 100 + cycle[0] * 60,
|
| 200 |
strftime=lambda *_: 'synthetic-time', gmtime=lambda: ())
|
| 201 |
-
ns = dict(_restore_sync_request_desks=lambda: None, RESYNC_STATE={'consecutiveFailures': 0}, _RESYNC_NOTICE=[None], _SEED_THREAD=None,
|
| 202 |
_configured_mirror_entities=lambda *_: None, freeze_notice=FREEZE_OFF,
|
| 203 |
_resolve_resync_cadence=lambda: dict(resolvedSeconds=60, manual=False,
|
| 204 |
tenant='synthetic', tenantSource='test', tenantSeconds=60,
|
|
@@ -520,7 +520,7 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 520 |
|
| 521 |
clock = SimpleNamespace(sleep=sleep, time=lambda: now,
|
| 522 |
strftime=lambda *_: 'synthetic-time', gmtime=lambda: ())
|
| 523 |
-
ns = dict(_restore_sync_request_desks=lambda: None, RESYNC_STATE={'consecutiveFailures': 0}, _RESYNC_NOTICE=[None], _SEED_THREAD=None,
|
| 524 |
_configured_mirror_entities=lambda *_: None,
|
| 525 |
freeze_notice=SimpleNamespace(enabled=lambda: frozen),
|
| 526 |
_resolve_resync_cadence=lambda: dict(
|
|
@@ -764,7 +764,8 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 764 |
from datetime import datetime
|
| 765 |
return datetime.fromisoformat(text.replace('Z', '+00:00')).timestamp()
|
| 766 |
|
| 767 |
-
def run_slot_loop(self, memory, *, boot, max_sleeps, tenant='royal-imports', config=None
|
|
|
|
| 768 |
"""Drive the real loop and its real slot resolver on a clock that advances at each wait."""
|
| 769 |
import odoo_relational as rel
|
| 770 |
source = ast.parse(Path(__file__).with_name('main.py').read_text(encoding='utf-8'))
|
|
@@ -790,12 +791,14 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 790 |
events.append(('mirror', now[0], manual_flag))
|
| 791 |
if manual_flag:
|
| 792 |
return None, None, None
|
|
|
|
|
|
|
| 793 |
return {'res_partner': {'phase': 'live', 'pulled': 0}}, {}, None
|
| 794 |
|
| 795 |
store = self.SlotStore(tenant, {rel.CONFIG_KEY: dict(config or {})})
|
| 796 |
-
clock = SimpleNamespace(sleep=wait, time=lambda: now[0],
|
| 797 |
strftime=lambda *_: 'synthetic-time', gmtime=lambda: ())
|
| 798 |
-
ns = dict(_restore_sync_request_desks=lambda: None, RESYNC_STATE={'consecutiveFailures': 0}, _RESYNC_NOTICE=[None], _SEED_THREAD=None,
|
| 799 |
_configured_mirror_entities=lambda *_: None, freeze_notice=FREEZE_OFF,
|
| 800 |
_resolve_resync_cadence=lambda: dict(
|
| 801 |
resolvedSeconds=86400, manual=False, tenant=tenant, tenantSource='test',
|
|
@@ -811,6 +814,9 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 811 |
_rebuild_meta_relational=lambda *_a, **_k: {},
|
| 812 |
_rebuild_amazon_relational=lambda *_a, **_k: {},
|
| 813 |
_resync_confirm_fresh=lambda *a: events.append(('fresh', now[0])))
|
|
|
|
|
|
|
|
|
|
| 814 |
nodes = _with_collaborators(source, nodes, ns)
|
| 815 |
exec(compile(ast.Module(body=nodes, type_ignores=[]), 'main.py:slot-loop', 'exec'), ns)
|
| 816 |
runtime = SimpleNamespace(get_runtime=lambda *_: store, tenant_for_store_path=lambda: tenant,
|
|
@@ -872,15 +878,58 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 872 |
self.assertNotIn(('amazon', boot, 'boot', False), events)
|
| 873 |
|
| 874 |
def test_h73_a_restart_inside_a_slot_pass_does_not_run_it_twice(self):
|
| 875 |
-
"""
|
|
|
|
| 876 |
stamp = self.utc('2026-10-24T06:00:01Z')
|
| 877 |
yesterday = self.utc('2026-10-23T06:30:00Z')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
events, sleeps, odoo = self.run_slot_loop(
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
boot=self.utc('2026-10-24T06:
|
| 882 |
self.assertEqual((odoo, sleeps), ([], [self.utc('2026-10-25T06:00:01Z')
|
| 883 |
-
- self.utc('2026-10-24T06:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
|
| 885 |
def test_h73_a_tenant_without_a_slot_keeps_the_cadence_loop(self):
|
| 886 |
"""H73 d: not tenant #0 and no stored time: the first pass runs at boot, then a cadence"""
|
|
@@ -919,5 +968,36 @@ class RankRefreshTests(unittest.TestCase):
|
|
| 919 |
'2026-10-25T07:30:00Z')
|
| 920 |
|
| 921 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
if __name__ == '__main__':
|
| 923 |
unittest.main()
|
|
|
|
| 198 |
# every pass would ask for a zero wait.
|
| 199 |
clock = SimpleNamespace(sleep=sleep, time=lambda: 100 + cycle[0] * 60,
|
| 200 |
strftime=lambda *_: 'synthetic-time', gmtime=lambda: ())
|
| 201 |
+
ns = dict(os=os, _restore_sync_request_desks=lambda: None, RESYNC_STATE={'consecutiveFailures': 0}, _RESYNC_NOTICE=[None], _SEED_THREAD=None,
|
| 202 |
_configured_mirror_entities=lambda *_: None, freeze_notice=FREEZE_OFF,
|
| 203 |
_resolve_resync_cadence=lambda: dict(resolvedSeconds=60, manual=False,
|
| 204 |
tenant='synthetic', tenantSource='test', tenantSeconds=60,
|
|
|
|
| 520 |
|
| 521 |
clock = SimpleNamespace(sleep=sleep, time=lambda: now,
|
| 522 |
strftime=lambda *_: 'synthetic-time', gmtime=lambda: ())
|
| 523 |
+
ns = dict(os=os, _restore_sync_request_desks=lambda: None, RESYNC_STATE={'consecutiveFailures': 0}, _RESYNC_NOTICE=[None], _SEED_THREAD=None,
|
| 524 |
_configured_mirror_entities=lambda *_: None,
|
| 525 |
freeze_notice=SimpleNamespace(enabled=lambda: frozen),
|
| 526 |
_resolve_resync_cadence=lambda: dict(
|
|
|
|
| 764 |
from datetime import datetime
|
| 765 |
return datetime.fromisoformat(text.replace('Z', '+00:00')).timestamp()
|
| 766 |
|
| 767 |
+
def run_slot_loop(self, memory, *, boot, max_sleeps, tenant='royal-imports', config=None,
|
| 768 |
+
reports=None, checkpoints=None):
|
| 769 |
"""Drive the real loop and its real slot resolver on a clock that advances at each wait."""
|
| 770 |
import odoo_relational as rel
|
| 771 |
source = ast.parse(Path(__file__).with_name('main.py').read_text(encoding='utf-8'))
|
|
|
|
| 791 |
events.append(('mirror', now[0], manual_flag))
|
| 792 |
if manual_flag:
|
| 793 |
return None, None, None
|
| 794 |
+
if reports:
|
| 795 |
+
return reports.pop(0), {}, None
|
| 796 |
return {'res_partner': {'phase': 'live', 'pulled': 0}}, {}, None
|
| 797 |
|
| 798 |
store = self.SlotStore(tenant, {rel.CONFIG_KEY: dict(config or {})})
|
| 799 |
+
clock = SimpleNamespace(sleep=wait, monotonic=lambda: now[0], time=lambda: now[0],
|
| 800 |
strftime=lambda *_: 'synthetic-time', gmtime=lambda: ())
|
| 801 |
+
ns = dict(os=os, _restore_sync_request_desks=lambda: None, RESYNC_STATE={'consecutiveFailures': 0}, _RESYNC_NOTICE=[None], _SEED_THREAD=None,
|
| 802 |
_configured_mirror_entities=lambda *_: None, freeze_notice=FREEZE_OFF,
|
| 803 |
_resolve_resync_cadence=lambda: dict(
|
| 804 |
resolvedSeconds=86400, manual=False, tenant=tenant, tenantSource='test',
|
|
|
|
| 814 |
_rebuild_meta_relational=lambda *_a, **_k: {},
|
| 815 |
_rebuild_amazon_relational=lambda *_a, **_k: {},
|
| 816 |
_resync_confirm_fresh=lambda *a: events.append(('fresh', now[0])))
|
| 817 |
+
if checkpoints is not None:
|
| 818 |
+
# H1: the held candidate's unfinished checkpoints, one answer per read.
|
| 819 |
+
ns['_odoo_backfill_checkpoints'] = lambda *_: checkpoints.pop(0)
|
| 820 |
nodes = _with_collaborators(source, nodes, ns)
|
| 821 |
exec(compile(ast.Module(body=nodes, type_ignores=[]), 'main.py:slot-loop', 'exec'), ns)
|
| 822 |
runtime = SimpleNamespace(get_runtime=lambda *_: store, tenant_for_store_path=lambda: tenant,
|
|
|
|
| 878 |
self.assertNotIn(('amazon', boot, 'boot', False), events)
|
| 879 |
|
| 880 |
def test_h73_a_restart_inside_a_slot_pass_does_not_run_it_twice(self):
|
| 881 |
+
"""H2: a slot pass that ended is not re-run; one killed before its end runs once, never twice"""
|
| 882 |
+
import odoo_relational as rel
|
| 883 |
stamp = self.utc('2026-10-24T06:00:01Z')
|
| 884 |
yesterday = self.utc('2026-10-23T06:30:00Z')
|
| 885 |
+
to_next_slot = self.utc('2026-10-25T06:00:01Z') - self.utc('2026-10-24T06:40:00Z')
|
| 886 |
+
base = {'passAt': yesterday, 'fullRebuildAt': yesterday, 'slotPassAt': stamp,
|
| 887 |
+
'fingerprints': {'res_partner': (3, 7)}}
|
| 888 |
+
# Ended: `slotDoneAt` after the claim, or (older memory) `passAt` after it. No Odoo call.
|
| 889 |
+
for ended in ({'slotDoneAt': self.utc('2026-10-24T06:30:00Z')},
|
| 890 |
+
{'passAt': self.utc('2026-10-24T06:30:00Z')}):
|
| 891 |
+
events, sleeps, odoo = self.run_slot_loop(
|
| 892 |
+
dict(base, **ended), boot=self.utc('2026-10-24T06:40:00Z'), max_sleeps=1)
|
| 893 |
+
self.assertEqual((odoo, sleeps), ([], [to_next_slot]))
|
| 894 |
+
# Killed: the end marker predates the claim. One pass at boot, stamped start and end.
|
| 895 |
+
boot = self.utc('2026-10-24T06:40:00Z')
|
| 896 |
+
events, sleeps, odoo = self.run_slot_loop(
|
| 897 |
+
dict(base, slotDoneAt=yesterday), boot=boot, max_sleeps=1)
|
| 898 |
+
self.assertEqual([e[1] for e in odoo if e[0] == 'mirror'], [boot])
|
| 899 |
+
memory = rel.read_resync_memory(self.slot_store)
|
| 900 |
+
self.assertEqual((memory['slotPassAt'], memory['slotDoneAt'], memory['slotResumedFor']),
|
| 901 |
+
(boot, boot, self.utc('2026-10-24T06:00:00Z')))
|
| 902 |
+
self.assertIn('never finished; running it once now', self.loop_output)
|
| 903 |
+
# Killed again after its one resume: no Odoo call until the next slot.
|
| 904 |
events, sleeps, odoo = self.run_slot_loop(
|
| 905 |
+
dict(base, slotPassAt=boot, slotDoneAt=yesterday,
|
| 906 |
+
slotResumedFor=self.utc('2026-10-24T06:00:00Z')),
|
| 907 |
+
boot=self.utc('2026-10-24T06:50:00Z'), max_sleeps=1)
|
| 908 |
self.assertEqual((odoo, sleeps), ([], [self.utc('2026-10-25T06:00:01Z')
|
| 909 |
+
- self.utc('2026-10-24T06:50:00Z')]))
|
| 910 |
+
self.assertNotIn('never finished', self.loop_output)
|
| 911 |
+
|
| 912 |
+
def test_h2_staging_memory_after_a_deploy_killed_the_slot_pass(self):
|
| 913 |
+
"""H2: claim 06:00:01Z, passAt the day before, boot 06:07Z: due once, then not due"""
|
| 914 |
+
import odoo_relational as rel
|
| 915 |
+
slot = rel.sync_slot(rel.read_config(self.SlotStore('royal-imports')))
|
| 916 |
+
claim, boot = self.utc('2026-10-27T06:00:01Z'), self.utc('2026-10-27T06:07:00Z')
|
| 917 |
+
memory = {'slotPassAt': claim, 'passAt': self.utc('2026-10-26T06:59:00Z'),
|
| 918 |
+
'slotDoneAt': None, 'slotResumedFor': None}
|
| 919 |
+
self.assertFalse(rel.slot_due(boot, slot, claim))
|
| 920 |
+
self.assertEqual(rel.slot_pass_killed(boot, slot, memory), self.utc('2026-10-27T06:00:00Z'))
|
| 921 |
+
resumed = dict(memory, slotResumedFor=self.utc('2026-10-27T06:00:00Z'))
|
| 922 |
+
self.assertIsNone(rel.slot_pass_killed(boot, slot, resumed))
|
| 923 |
+
# The next day's slot is due by the ordinary rule, so the guard holds for one slot only.
|
| 924 |
+
self.assertTrue(rel.slot_due(self.utc('2026-10-28T06:00:00Z'), slot, claim))
|
| 925 |
+
# The loop runs the killed pass once at boot and logs the one resume line.
|
| 926 |
+
events, sleeps, odoo = self.run_slot_loop(
|
| 927 |
+
dict(memory, fullRebuildAt=memory['passAt'], fingerprints={'res_partner': (3, 7)}),
|
| 928 |
+
boot=boot, max_sleeps=1)
|
| 929 |
+
self.assertEqual([e[1] for e in odoo if e[0] == 'mirror'], [boot])
|
| 930 |
+
self.assertIn('the 13:00 Asia/Jakarta slot pass started at 2026-10-27T06:00:01Z never '
|
| 931 |
+
'finished; running it once now', self.loop_output)
|
| 932 |
+
self.assertEqual(sleeps, [self.utc('2026-10-28T06:00:01Z') - boot])
|
| 933 |
|
| 934 |
def test_h73_a_tenant_without_a_slot_keeps_the_cadence_loop(self):
|
| 935 |
"""H73 d: not tenant #0 and no stored time: the first pass runs at boot, then a cadence"""
|
|
|
|
| 968 |
'2026-10-25T07:30:00Z')
|
| 969 |
|
| 970 |
|
| 971 |
+
def test_h1_a_held_backfill_that_moved_queues_one_odoo_only_pass(self):
|
| 972 |
+
"""H1: a held backfill that moved runs again 60s later, Odoo only and unstamped; no progress stops"""
|
| 973 |
+
import odoo_relational as rel
|
| 974 |
+
last = self.utc('2026-10-22T06:05:00Z')
|
| 975 |
+
boot = self.utc('2026-10-24T09:00:00Z')
|
| 976 |
+
next_slot = self.utc('2026-10-25T06:00:00Z')
|
| 977 |
+
memory = {'passAt': last, 'fullRebuildAt': last, 'fingerprints': {'res_partner': (3, 7)}}
|
| 978 |
+
held = {'account_move_line': {'phase': 'backfill', 'pulled': 0}}
|
| 979 |
+
marker = 'account_move_line.cols.amount_residual'
|
| 980 |
+
before = ((marker, 'running', 500, None, 100_000),)
|
| 981 |
+
after = ((marker, 'running', 900, None, 200_000),)
|
| 982 |
+
# Moved: the slot pass queues one continuation, which moves nothing and ends the chain.
|
| 983 |
+
events, sleeps, odoo = self.run_slot_loop(
|
| 984 |
+
memory, boot=boot, max_sleeps=2, reports=[held, held],
|
| 985 |
+
checkpoints=[before, after, after, after])
|
| 986 |
+
self.assertEqual([e[1] for e in odoo if e[0] == 'mirror'], [boot, boot + 60])
|
| 987 |
+
self.assertEqual(sleeps, [60.0, next_slot + 1 - (boot + 60)])
|
| 988 |
+
self.assertEqual([e for e in events if e[0] in ('meta', 'amazon', 'rebuild')], [])
|
| 989 |
+
stamps = rel.read_resync_memory(self.slot_store)
|
| 990 |
+
self.assertEqual((stamps['slotPassAt'], stamps['slotDoneAt']), (boot, boot))
|
| 991 |
+
self.assertEqual(self.loop_output.count('odoo backfill continues:'), 1)
|
| 992 |
+
self.assertIn('odoo backfill continues: account_move_line at 200,000 rows; next bounded '
|
| 993 |
+
'pass queued (1 of 24 today)', self.loop_output)
|
| 994 |
+
# No progress: the held slot pass queues nothing and waits for the next slot.
|
| 995 |
+
events, sleeps, odoo = self.run_slot_loop(
|
| 996 |
+
memory, boot=boot, max_sleeps=1, reports=[held], checkpoints=[before, before])
|
| 997 |
+
self.assertEqual([e[1] for e in odoo if e[0] == 'mirror'], [boot])
|
| 998 |
+
self.assertEqual(sleeps, [next_slot + 1 - boot])
|
| 999 |
+
self.assertNotIn('odoo backfill continues', self.loop_output)
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
if __name__ == '__main__':
|
| 1003 |
unittest.main()
|
platform/modules/aged_stock.py
CHANGED
|
@@ -900,6 +900,19 @@ def _first_open(st, now=None):
|
|
| 900 |
return READING if (queued or {}).get("state") in ("queued", "running") else NOT_READY
|
| 901 |
|
| 902 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 903 |
def summary(tenant_key, *, offset=0, limit=24, st=None):
|
| 904 |
"""Aggregate fees and counts in SQL and return one month page without SKU rows."""
|
| 905 |
st = _rt(tenant_key, st)
|
|
@@ -908,7 +921,7 @@ def summary(tenant_key, *, offset=0, limit=24, st=None):
|
|
| 908 |
doc = out.pop("meta") or {}
|
| 909 |
ready = doc.get("state") == "ready"
|
| 910 |
waiting = None if ready else (doc.get("message") or NOT_READY)
|
| 911 |
-
if not ready and not doc.get("state"):
|
| 912 |
waiting = _first_open(st)
|
| 913 |
return {**out, "trend": out.get("trend") or {}, "totals": out.get("totals") or {}, "monthLimit": limit,
|
| 914 |
"ready": ready, "notReady": waiting,
|
|
|
|
| 900 |
return READING if (queued or {}).get("state") in ("queued", "running") else NOT_READY
|
| 901 |
|
| 902 |
|
| 903 |
+
def _stale_wait(st, doc, now=None):
|
| 904 |
+
"""A not ready doc whose queued refresh found nothing more than the hold ago is read again.
|
| 905 |
+
|
| 906 |
+
That refresh may have run while the mirror was still restoring at boot."""
|
| 907 |
+
if doc.get("state") != "not_ready":
|
| 908 |
+
return False
|
| 909 |
+
pending = _doc(st, KEY_REFRESH)
|
| 910 |
+
if pending.get("state") != "done" or (pending.get("result") or {}).get("state") != "not_ready":
|
| 911 |
+
return False
|
| 912 |
+
stamp = time.time() if now is None else now
|
| 913 |
+
return stamp - float(pending.get("finishedAt") or 0) >= REFRESH_HOLD_SECONDS
|
| 914 |
+
|
| 915 |
+
|
| 916 |
def summary(tenant_key, *, offset=0, limit=24, st=None):
|
| 917 |
"""Aggregate fees and counts in SQL and return one month page without SKU rows."""
|
| 918 |
st = _rt(tenant_key, st)
|
|
|
|
| 921 |
doc = out.pop("meta") or {}
|
| 922 |
ready = doc.get("state") == "ready"
|
| 923 |
waiting = None if ready else (doc.get("message") or NOT_READY)
|
| 924 |
+
if not ready and (not doc.get("state") or _stale_wait(st, doc)):
|
| 925 |
waiting = _first_open(st)
|
| 926 |
return {**out, "trend": out.get("trend") or {}, "totals": out.get("totals") or {}, "monthLimit": limit,
|
| 927 |
"ready": ready, "notReady": waiting,
|
platform/modules/opportunity_finder.py
CHANGED
|
@@ -60,6 +60,9 @@ WAITING = "Amazon has not finished the week ending {day} yet, so the finder read
|
|
| 60 |
WAITING_NEXT = "Amazon has not finished the newest week yet, so the finder reads it at the next sync."
|
| 61 |
REFUSED = ("Amazon refused the brand analytics report. Check Brand Registry and the Brand Analytics role "
|
| 62 |
"in Seller Central.")
|
|
|
|
|
|
|
|
|
|
| 63 |
#: `_sync_state` markers of the brand analytics pass, matched bare or behind an account prefix.
|
| 64 |
WAITING_KEY = "amzn_waiting_brand_analytics"
|
| 65 |
REFUSED_KEY = "amzn_refused_brand_analytics"
|
|
@@ -366,7 +369,7 @@ def _day_words(value):
|
|
| 366 |
|
| 367 |
|
| 368 |
def ba_marker(rows):
|
| 369 |
-
"""("waiting", day words or None), ("refused", None) or None from (entity, detail, updated_at) rows.
|
| 370 |
|
| 371 |
The newest of the waiting and refused markers wins. A refusal whose text says the week is not
|
| 372 |
available yet is Amazon still building that week, not a refusal."""
|
|
@@ -390,7 +393,10 @@ def ba_marker(rows):
|
|
| 390 |
or _found(r"end date \[(\d{4}-\d{2}-\d{2})\]", said))
|
| 391 |
if key == WAITING_KEY or "not available yet" in said.lower():
|
| 392 |
return "waiting", _day_words(end)
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
|
| 396 |
def _found(pattern, text):
|
|
@@ -419,7 +425,9 @@ def not_synced(cur, columns):
|
|
| 419 |
if marker and marker[0] == "refused":
|
| 420 |
return [REFUSED]
|
| 421 |
out = []
|
| 422 |
-
if marker:
|
|
|
|
|
|
|
| 423 |
out.append(WAITING.format(day=marker[1]) if marker[1] else WAITING_NEXT)
|
| 424 |
if held:
|
| 425 |
out.append(NO_FIELDS if set(BA_NEED) - set(columns) - {"_period_start"} else NO_WEEK)
|
|
|
|
| 60 |
WAITING_NEXT = "Amazon has not finished the newest week yet, so the finder reads it at the next sync."
|
| 61 |
REFUSED = ("Amazon refused the brand analytics report. Check Brand Registry and the Brand Analytics role "
|
| 62 |
"in Seller Central.")
|
| 63 |
+
STORE_FAILED = "The last brand analytics report could not be stored, so the next Amazon sync loads it again."
|
| 64 |
+
#: `amazonStatus` values that are Amazon's own refusal, as `amazon_store._sync_problem` records them.
|
| 65 |
+
AMAZON_REFUSALS = ("FATAL", "CANCELLED", "NOT_OFFERED")
|
| 66 |
#: `_sync_state` markers of the brand analytics pass, matched bare or behind an account prefix.
|
| 67 |
WAITING_KEY = "amzn_waiting_brand_analytics"
|
| 68 |
REFUSED_KEY = "amzn_refused_brand_analytics"
|
|
|
|
| 369 |
|
| 370 |
|
| 371 |
def ba_marker(rows):
|
| 372 |
+
"""("waiting", day words or None), ("refused" or "failed", None) or None from (entity, detail, updated_at) rows.
|
| 373 |
|
| 374 |
The newest of the waiting and refused markers wins. A refusal whose text says the week is not
|
| 375 |
available yet is Amazon still building that week, not a refusal."""
|
|
|
|
| 393 |
or _found(r"end date \[(\d{4}-\d{2}-\d{2})\]", said))
|
| 394 |
if key == WAITING_KEY or "not available yet" in said.lower():
|
| 395 |
return "waiting", _day_words(end)
|
| 396 |
+
# Only Amazon's own refusal names Brand Registry; a failure on our side (memory, a parse) reads as one.
|
| 397 |
+
if _text(body.get("amazonStatus")).upper() in AMAZON_REFUSALS or re.search(r"\b403\b", said):
|
| 398 |
+
return "refused", None
|
| 399 |
+
return "failed", None
|
| 400 |
|
| 401 |
|
| 402 |
def _found(pattern, text):
|
|
|
|
| 425 |
if marker and marker[0] == "refused":
|
| 426 |
return [REFUSED]
|
| 427 |
out = []
|
| 428 |
+
if marker and marker[0] == "failed":
|
| 429 |
+
out.append(STORE_FAILED)
|
| 430 |
+
elif marker:
|
| 431 |
out.append(WAITING.format(day=marker[1]) if marker[1] else WAITING_NEXT)
|
| 432 |
if held:
|
| 433 |
out.append(NO_FIELDS if set(BA_NEED) - set(columns) - {"_period_start"} else NO_WEEK)
|
platform/modules/ranking_diagnostic.py
CHANGED
|
@@ -114,6 +114,10 @@ BA_WAITING = ("Amazon has not finished the week ending {day} yet, so search-term
|
|
| 114 |
BA_WAITING_NEXT = "Amazon has not finished the newest week yet, so search-term share is checked after the next sync."
|
| 115 |
BA_REFUSED = ("Amazon refused the brand analytics report, so search-term share is not checked. Check Brand "
|
| 116 |
"Registry and the Brand Analytics role in Seller Central.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
#: `_sync_state` markers of the brand analytics pass, matched bare or behind an account prefix.
|
| 118 |
WAITING_KEY = "amzn_waiting_brand_analytics"
|
| 119 |
REFUSED_KEY = "amzn_refused_brand_analytics"
|
|
@@ -121,6 +125,7 @@ REFUSED_KEY = "amzn_refused_brand_analytics"
|
|
| 121 |
BA_NEED = ("clicked_asin", "click_share")
|
| 122 |
#: Stored lines that name the brand analytics source, read again from the mirror on screen.
|
| 123 |
_BA_PREFIXES = ("Brand analytics ", "Amazon has not finished the ", "Amazon refused the brand analytics",
|
|
|
|
| 124 |
"ut_amzn_brand_analytics ")
|
| 125 |
_OLD_MISSING = re.compile(r"^ut_(amzn_[a-z_]+) has not synced yet, so (.+) is not checked\.$")
|
| 126 |
|
|
@@ -472,7 +477,7 @@ def _day_words(value):
|
|
| 472 |
|
| 473 |
|
| 474 |
def ba_marker(rows):
|
| 475 |
-
"""("waiting", day words or None), ("refused", None) or None from (entity, detail, updated_at) rows.
|
| 476 |
|
| 477 |
The newest of the waiting and refused markers wins. A refusal that says the week is not available
|
| 478 |
yet is Amazon still building that week, not a refusal."""
|
|
@@ -496,7 +501,10 @@ def ba_marker(rows):
|
|
| 496 |
or _found(r"end date \[(\d{4}-\d{2}-\d{2})\]", said))
|
| 497 |
if key == WAITING_KEY or "not available yet" in said.lower():
|
| 498 |
return "waiting", _day_words(end)
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
| 500 |
|
| 501 |
|
| 502 |
def _markers(cur):
|
|
@@ -523,7 +531,9 @@ def ba_lines(cur):
|
|
| 523 |
if marker and marker[0] == "refused":
|
| 524 |
return [BA_REFUSED]
|
| 525 |
out = []
|
| 526 |
-
if marker:
|
|
|
|
|
|
|
| 527 |
out.append(BA_WAITING.format(day=marker[1]) if marker[1] else BA_WAITING_NEXT)
|
| 528 |
if held:
|
| 529 |
out.append(BA_NO_FIELDS if set(BA_NEED) - cols else BA_NO_WEEK)
|
|
|
|
| 114 |
BA_WAITING_NEXT = "Amazon has not finished the newest week yet, so search-term share is checked after the next sync."
|
| 115 |
BA_REFUSED = ("Amazon refused the brand analytics report, so search-term share is not checked. Check Brand "
|
| 116 |
"Registry and the Brand Analytics role in Seller Central.")
|
| 117 |
+
BA_STORE_FAILED = ("The last brand analytics report could not be stored, so search-term share is checked after the "
|
| 118 |
+
"next sync.")
|
| 119 |
+
#: `amazonStatus` values that are Amazon's own refusal, as `amazon_store._sync_problem` records them.
|
| 120 |
+
AMAZON_REFUSALS = ("FATAL", "CANCELLED", "NOT_OFFERED")
|
| 121 |
#: `_sync_state` markers of the brand analytics pass, matched bare or behind an account prefix.
|
| 122 |
WAITING_KEY = "amzn_waiting_brand_analytics"
|
| 123 |
REFUSED_KEY = "amzn_refused_brand_analytics"
|
|
|
|
| 125 |
BA_NEED = ("clicked_asin", "click_share")
|
| 126 |
#: Stored lines that name the brand analytics source, read again from the mirror on screen.
|
| 127 |
_BA_PREFIXES = ("Brand analytics ", "Amazon has not finished the ", "Amazon refused the brand analytics",
|
| 128 |
+
"The last brand analytics report ",
|
| 129 |
"ut_amzn_brand_analytics ")
|
| 130 |
_OLD_MISSING = re.compile(r"^ut_(amzn_[a-z_]+) has not synced yet, so (.+) is not checked\.$")
|
| 131 |
|
|
|
|
| 477 |
|
| 478 |
|
| 479 |
def ba_marker(rows):
|
| 480 |
+
"""("waiting", day words or None), ("refused" or "failed", None) or None from (entity, detail, updated_at) rows.
|
| 481 |
|
| 482 |
The newest of the waiting and refused markers wins. A refusal that says the week is not available
|
| 483 |
yet is Amazon still building that week, not a refusal."""
|
|
|
|
| 501 |
or _found(r"end date \[(\d{4}-\d{2}-\d{2})\]", said))
|
| 502 |
if key == WAITING_KEY or "not available yet" in said.lower():
|
| 503 |
return "waiting", _day_words(end)
|
| 504 |
+
# Only Amazon's own refusal names Brand Registry; a failure on our side (memory, a parse) reads as one.
|
| 505 |
+
if _text(body.get("amazonStatus")).upper() in AMAZON_REFUSALS or re.search(r"\b403\b", said):
|
| 506 |
+
return "refused", None
|
| 507 |
+
return "failed", None
|
| 508 |
|
| 509 |
|
| 510 |
def _markers(cur):
|
|
|
|
| 531 |
if marker and marker[0] == "refused":
|
| 532 |
return [BA_REFUSED]
|
| 533 |
out = []
|
| 534 |
+
if marker and marker[0] == "failed":
|
| 535 |
+
out.append(BA_STORE_FAILED)
|
| 536 |
+
elif marker:
|
| 537 |
out.append(BA_WAITING.format(day=marker[1]) if marker[1] else BA_WAITING_NEXT)
|
| 538 |
if held:
|
| 539 |
out.append(BA_NO_FIELDS if set(BA_NEED) - cols else BA_NO_WEEK)
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
08bbb300e0e19bb909fdc8e2c95b2d781d569aaf303800692b2d3e413771cf5d
|
web/src/connectors/ConnectorsPage.tsx
CHANGED
|
@@ -298,6 +298,31 @@ export function useConnectorSyncStatus(connectorKey: string, connectionId?: stri
|
|
| 298 |
return { status: current?.status ?? null, problem: current?.problem ?? "" };
|
| 299 |
}
|
| 300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
/** Keep the status line mounted while the drawer loads or refreshes its database page. */
|
| 302 |
export function ConnectorSyncStatusLine({ status, problem = "" }: {
|
| 303 |
status: ConnectorSyncReading | null; problem?: string;
|
|
@@ -900,6 +925,23 @@ export default function ConnectorsPage({
|
|
| 900 |
});
|
| 901 |
return () => controller.abort();
|
| 902 |
}, [hasOdooCard]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 903 |
|
| 904 |
/**
|
| 905 |
* ⛔⛔ THE ADMIN ANSWER, AND IT IS KEPT OUT OF `load` ON PURPOSE. Folding a failed meta read
|
|
@@ -1049,7 +1091,7 @@ export default function ConnectorsPage({
|
|
| 1049 |
onKeychain={onKeychain}
|
| 1050 |
onOpen={() => openConnector(row)}
|
| 1051 |
onPullReviews={pullHandler(row)}
|
| 1052 |
-
syncWarnings={row
|
| 1053 |
catchUp={sourceCard(row)}
|
| 1054 |
catchUpError={row.key === "odoo" ? catchUpStatus.error : undefined}
|
| 1055 |
catchUpLoading={row.key === "odoo" && catchUpStatus.loading}
|
|
@@ -1072,7 +1114,7 @@ export default function ConnectorsPage({
|
|
| 1072 |
onKeychain={onKeychain}
|
| 1073 |
onOpen={() => openConnector(row)}
|
| 1074 |
onPullReviews={pullHandler(row)}
|
| 1075 |
-
syncWarnings={row
|
| 1076 |
catchUp={sourceCard(row)}
|
| 1077 |
catchUpError={row.key === "odoo" ? catchUpStatus.error : undefined}
|
| 1078 |
catchUpLoading={row.key === "odoo" && catchUpStatus.loading}
|
|
|
|
| 298 |
return { status: current?.status ?? null, problem: current?.problem ?? "" };
|
| 299 |
}
|
| 300 |
|
| 301 |
+
/** Daily sources whose sync route reports `stale` on Odoo's cadence rule, with the name a card shows. */
|
| 302 |
+
const DAILY_SOURCE_NAMES: Record<string, string> = { amazon_sp: "Amazon", meta_ads: "Meta" };
|
| 303 |
+
|
| 304 |
+
/** The card warning for one sync reading, PURE: none unless the route says a completed sync is stale. */
|
| 305 |
+
export function staleSyncWarnings(name: string, body: unknown): string[] {
|
| 306 |
+
if (!body || typeof body !== "object") return [];
|
| 307 |
+
const { stale, lastCompletedAt } = body as { stale?: unknown; lastCompletedAt?: unknown };
|
| 308 |
+
if (stale !== true || typeof lastCompletedAt !== "string") return [];
|
| 309 |
+
return [`${name} data is stale: last synced ${syncDate(lastCompletedAt)}`];
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
/** One read of a daily source's sync route. A failed read is no warning, never a thrown error. */
|
| 313 |
+
async function dailySyncWarnings(connectorKey: string, signal: AbortSignal): Promise<string[]> {
|
| 314 |
+
try {
|
| 315 |
+
const res = await fetch(`${API_V1}/connectors/${encodeURIComponent(connectorKey)}/sync`, {
|
| 316 |
+
credentials: CREDENTIALS, signal,
|
| 317 |
+
});
|
| 318 |
+
if (!res.ok) return [];
|
| 319 |
+
const body: unknown = await res.json().catch(() => null);
|
| 320 |
+
return staleSyncWarnings(DAILY_SOURCE_NAMES[connectorKey] ?? connectorKey, body);
|
| 321 |
+
} catch {
|
| 322 |
+
return [];
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
/** Keep the status line mounted while the drawer loads or refreshes its database page. */
|
| 327 |
export function ConnectorSyncStatusLine({ status, problem = "" }: {
|
| 328 |
status: ConnectorSyncReading | null; problem?: string;
|
|
|
|
| 925 |
});
|
| 926 |
return () => controller.abort();
|
| 927 |
}, [hasOdooCard]);
|
| 928 |
+
const dailySourceKeys = load.phase === "ready"
|
| 929 |
+
? load.rows.filter((row) => row.key in DAILY_SOURCE_NAMES && row.state === "connected")
|
| 930 |
+
.map((row) => row.key).join(",")
|
| 931 |
+
: "";
|
| 932 |
+
const [dailyWarnings, setDailyWarnings] = useState<Record<string, string[]>>({});
|
| 933 |
+
useEffect(() => {
|
| 934 |
+
if (!dailySourceKeys) return;
|
| 935 |
+
const controller = new AbortController();
|
| 936 |
+
const keys = dailySourceKeys.split(",");
|
| 937 |
+
void Promise.all(keys.map((key) => dailySyncWarnings(key, controller.signal))).then((lines) => {
|
| 938 |
+
if (!controller.signal.aborted) {
|
| 939 |
+
setDailyWarnings(Object.fromEntries(keys.map((key, index) => [key, lines[index]])));
|
| 940 |
+
}
|
| 941 |
+
});
|
| 942 |
+
return () => controller.abort();
|
| 943 |
+
}, [dailySourceKeys]);
|
| 944 |
+
const cardWarnings = (row: ConnectorRow) => row.key === "odoo" ? odooWarnings : dailyWarnings[row.key];
|
| 945 |
|
| 946 |
/**
|
| 947 |
* ⛔⛔ THE ADMIN ANSWER, AND IT IS KEPT OUT OF `load` ON PURPOSE. Folding a failed meta read
|
|
|
|
| 1091 |
onKeychain={onKeychain}
|
| 1092 |
onOpen={() => openConnector(row)}
|
| 1093 |
onPullReviews={pullHandler(row)}
|
| 1094 |
+
syncWarnings={cardWarnings(row)}
|
| 1095 |
catchUp={sourceCard(row)}
|
| 1096 |
catchUpError={row.key === "odoo" ? catchUpStatus.error : undefined}
|
| 1097 |
catchUpLoading={row.key === "odoo" && catchUpStatus.loading}
|
|
|
|
| 1114 |
onKeychain={onKeychain}
|
| 1115 |
onOpen={() => openConnector(row)}
|
| 1116 |
onPullReviews={pullHandler(row)}
|
| 1117 |
+
syncWarnings={cardWarnings(row)}
|
| 1118 |
catchUp={sourceCard(row)}
|
| 1119 |
catchUpError={row.key === "odoo" ? catchUpStatus.error : undefined}
|
| 1120 |
catchUpLoading={row.key === "odoo" && catchUpStatus.loading}
|