File indexing completed on 2026-12-02 10:28:16
0001 """
0002 Shared pieces of the task command log, ATLAS_PANDA.TASKS_COMMANDLOG.
0003
0004 The API decorator (request_validation in pandaserver/api/v1/common.py) writes a row for each
0005 task command it receives, before the command runs, and puts the row's key in
0006 current_task_command while the command runs. The TaskBuffer methods that register a command
0007 for JEDI in PRODSYS_COMM read the key there and pass it on to the DBProxy, which marks the
0008 same row as queued in the transaction that registers the command. The key travels as an
0009 explicit argument from TaskBuffer on, because the DBProxy may run in another process
0010 (ConBridge), where this context is not seen.
0011
0012 The status of a row says where the command is:
0013
0014 received --+-- the API responded ---------------------------> responded
0015 +-- the API ended with an exception -------------> error
0016 +-- registered for JEDI in PRODSYS_COMM ---------> queued --+-- JEDI took it ----------> accepted
0017 +-- JEDI rejected it ------> rejected
0018 +-- a later command came --> superseded
0019
0020 Each writer moves a row only from the status it expects, so the writes may land in any
0021 order, e.g. JEDI may take a command before the API has recorded its response.
0022 """
0023
0024 import datetime
0025 from contextvars import ContextVar
0026 from typing import TypedDict
0027
0028 STATUS_RECEIVED = "received"
0029 STATUS_RESPONDED = "responded"
0030 STATUS_ERROR = "error"
0031 STATUS_QUEUED = "queued"
0032 STATUS_ACCEPTED = "accepted"
0033 STATUS_REJECTED = "rejected"
0034 STATUS_SUPERSEDED = "superseded"
0035
0036
0037 class TaskCommandKey(TypedDict):
0038 """The key of the rows a request wrote: their COMMAND_ID and their COMMAND_TIME, the partition key."""
0039
0040 command_id: int
0041 command_time: datetime.datetime
0042
0043
0044
0045 current_task_command: ContextVar[TaskCommandKey | None] = ContextVar("current_task_command", default=None)