jroachgolf84 commented on code in PR #67299:
URL: https://github.com/apache/airflow/pull/67299#discussion_r3367303701


##########
airflow-core/docs/core-concepts/task-store.rst:
##########
@@ -0,0 +1,278 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+.. _concepts:task-store:
+
+.. spelling:word-list::
+
+   intra
+   Intra
+   checkpointing
+
+Task Store
+==========
+
+.. versionadded:: 3.3
+
+Task store is a persistent key/value store scoped to a single task instance 
(``dag_id`` + ``run_id`` + ``task_id`` + ``map_index``). It survives worker 
crashes and task retries within the same Dag run, making it suitable for 
storing external job IDs, intra-task checkpoints, and progress metadata.
+
+Data persisted via task store is accessed through the task context via 
``context["task_store"]`` and exposes four methods: ``get``, ``set``, 
``delete``, and ``clear``.
+
+
+Accessing task store
+--------------------
+
+Inside any ``@task``-decorated function or ``BaseOperator.execute()`` method, 
task store is available through the ``context`` dictionary via the 
``task_store`` key. From there, it can be used to retrieve, set, delete, or 
clear data for a specific key-value pair. In this example, the ``job_id`` is 
retrieved from task store, then updated, before being deleted. All data for 
that task is then removed using the ``clear`` method.
+
+.. code-block:: python
+
+    from airflow.sdk import task
+    import random
+
+
+    @task
+    def my_task(**context):
+        # Retrieve task_store from context
+        task_store = context["task_store"]
+        my_value = task_store.get("my_key", default="my_default_key")
+
+        # Set the new value
+        new_value = f"It is {random.randint(1, 12 + 1)} o'clock"
+        task_store.set("my_key", new_value)
+
+        # Delete the value
+        task_store.delete("my_key")
+
+        # Clear all store entries for the task
+        task_store.clear()
+
+Reference
+---------
+
+``get(key, default)``
+~~~~~~~~~~~~~~~~~~~~~
+
+Returns the stored JSON value, or the ``default`` value if the key does not 
exist.
+
+.. code-block:: python
+
+    value = task_store.get(
+        "job_id", default="123456789"
+    )  # returns the value associated with `job_id` or the default value
+
+``set(key, value, *, retention=None)``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Writes or overwrites a value for the specified key. Note, ``value`` can be any 
JSON-compatible type, except for ``None``. This includes:
+
+* ``str``
+* ``int``
+* ``float``
+* ``bool``
+* ``list``
+* ``dict``
+
+The optional ``retention`` argument controls when the key expires:
+
+* ``timedelta(...)``: expire after the given duration from the time of the 
write (e.g. ``timedelta(hours=6)``). The expiry timestamp is computed on the 
worker before the value is sent to the API server.
+* ``NEVER_EXPIRE``: the key never expires and is skipped during garbage 
collection, regardless of the global ``[state_store] default_retention_days`` 
setting.
+* ``None`` (default): fall back to the global ``[state_store] 
default_retention_days`` config.
+
+.. important::
+
+   ``retention`` accepts only a :class:`~datetime.timedelta`, not a plain 
integer number of days. Passing an integer raises a ``TypeError``.
+
+   .. code-block:: python
+
+       # correct
+       task_store.set("key", "val", retention=timedelta(days=7))
+
+       # wrong — raises TypeError
+       task_store.set("key", "val", retention=7)
+
+``NEVER_EXPIRE`` sentinel
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Import ``NEVER_EXPIRE`` from ``airflow.sdk.execution_time.context``:

Review Comment:
   Resolved in next commit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to