generated from dbt-labs/dbt-oss-template
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "invocation_started_at" global field (#246)
* Add invocation_started_at * Changie * Add unit test
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Add "invocation_started_at" global field | ||
time: 2025-02-13T13:52:45.156677-05:00 | ||
custom: | ||
Author: gshank | ||
Issue: "245" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import uuid | ||
from datetime import datetime | ||
|
||
_INVOCATION_ID = str(uuid.uuid4()) | ||
_INVOCATION_STARTED_AT = datetime.utcnow() | ||
|
||
|
||
def get_invocation_id() -> str: | ||
return _INVOCATION_ID | ||
|
||
|
||
def get_invocation_started_at() -> datetime: | ||
return _INVOCATION_STARTED_AT | ||
|
||
|
||
def reset_invocation_id() -> None: | ||
global _INVOCATION_ID | ||
global _INVOCATION_ID, _INVOCATION_STARTED_AT | ||
_INVOCATION_ID = str(uuid.uuid4()) | ||
_INVOCATION_STARTED_AT = datetime.utcnow() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from dbt_common.invocation import get_invocation_id, get_invocation_started_at, reset_invocation_id | ||
|
||
|
||
def test_invocation_started_at(): | ||
inv_id = get_invocation_id() | ||
assert inv_id | ||
inv_start = get_invocation_started_at() | ||
assert inv_start | ||
|
||
reset_invocation_id() | ||
inv_start != get_invocation_started_at() | ||
inv_id != get_invocation_id() |