jason810496 commented on code in PR #73618:
URL: https://github.com/apache/airflow/pull/73618#discussion_r4193232762
##########
ts-sdk/src/sdk/client-types.ts:
##########
@@ -50,6 +50,26 @@ export interface SetXComOpts {
mapIndex?: number | null;
}
+/** Sentinel for {@link SetTaskStateStoreOpts.retentionMs}: store the key with
no expiry. */
+export const NEVER_EXPIRE: number = Number.POSITIVE_INFINITY;
Review Comment:
Would it be better to introduce a dedicated symbol to avoid the case of
accidentally computing to Infinity (e.g. dividing by zero)?
##########
ts-sdk/src/sdk/client.ts:
##########
@@ -88,6 +93,46 @@ export interface TaskClient {
*/
setXCom(opts: SetXComOpts): Promise<void>;
+ /**
+ * Look up a value in this task instance's state store.
+ *
+ * Returns `null` when the key is missing. Throws on any other error.
+ *
+ * The generic `T` lets callers narrow the return type when the shape is
+ * known.
+ *
+ * @throws {@link TypeError} when `key` is not a string.
+ * @throws {@link RangeError} when `key` is empty.
+ */
+ getTaskStateStore<T = unknown>(key: string): Promise<T | null>;
Review Comment:
I'd like to make the overall interface lean toward the shape of the Python
and the Java side.
```ts
export interface TaskStateStore {
get<T = unknown>(key: string): Promise<T | null>;
set(key: string, value: NonNullable<JsonValue>, opts?: { retentionMs?:
number }): Promise<void>;
delete(key: string): Promise<void>;
clear(): Promise<void>;
}
export interface TaskClient {
// ...existing flat methods
readonly taskStateStore: TaskStateStore;
}
const store = getClient().taskStateStore;
let jobId = await store.get<string>("job_id");
if (jobId == null) {
jobId = await submit();
await store.set("job_id", jobId, { retentionMs: NEVER_EXPIRE });
}
```
--
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]