Skip to content

Commit 148c964

Browse files
committed
[gql] latest event id resolver for Asset so that we can order by id
1 parent 92af968 commit 148c964

File tree

2 files changed

+26
-0
lines changed
  • python_modules
    • dagster/dagster/_core/storage/event_log
    • dagster-graphql/dagster_graphql/schema/pipelines

2 files changed

+26
-0
lines changed

python_modules/dagster-graphql/dagster_graphql/schema/pipelines/pipeline.py

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
RunRecord,
2222
RunsFilter,
2323
)
24+
from dagster._core.storage.event_log.base import AssetRecord
2425
from dagster._core.storage.tags import REPOSITORY_LABEL_TAG, RUN_METRIC_TAGS, TagType, get_tag_type
2526
from dagster._core.workspace.permissions import Permissions
2627
from dagster._utils.tags import get_boolean_tag_value
@@ -247,6 +248,7 @@ class GrapheneAsset(graphene.ObjectType):
247248
cursor=graphene.String(),
248249
)
249250
definition = graphene.Field("dagster_graphql.schema.asset_graph.GrapheneAssetNode")
251+
latestEventId = graphene.Field(graphene.Int)
250252

251253
class Meta:
252254
name = "Asset"
@@ -389,6 +391,12 @@ def resolve_assetObservations(
389391
)
390392
]
391393

394+
async def resolve_LatestEventId(self, graphene_info):
395+
asset_record = await AssetRecord.gen(graphene_info.context, self.key)
396+
if asset_record:
397+
return asset_record.asset_entry.last_event_storage_id
398+
return None
399+
392400

393401
class GrapheneEventConnection(graphene.ObjectType):
394402
class Meta:

python_modules/dagster/dagster/_core/storage/event_log/base.py

+18
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ def last_observation(self) -> Optional["EventLogEntry"]:
130130
return None
131131
return self.last_observation_record.event_log_entry
132132

133+
@property
134+
def last_observation_storage_id(self) -> Optional[int]:
135+
if self.last_observation_record is None:
136+
return None
137+
return self.last_observation_record.storage_id
138+
133139
@property
134140
def last_materialization_storage_id(self) -> Optional[int]:
135141
if self.last_materialization_record is None:
@@ -148,6 +154,18 @@ def last_failed_to_materialize_storage_id(self) -> Optional[int]:
148154
return None
149155
return self.last_failed_to_materialize_record.storage_id
150156

157+
@property
158+
def last_event_storage_id(self) -> Optional[int]:
159+
"""Get the storage id of the latest event for this asset."""
160+
event_ids = [
161+
self.last_materialization_storage_id,
162+
self.last_observation_storage_id,
163+
self.last_failed_to_materialize_storage_id,
164+
self.last_planned_materialization_storage_id,
165+
]
166+
event_ids = [event_id for event_id in event_ids if event_id is not None]
167+
return max(event_ids) if event_ids else None
168+
151169

152170
class AssetRecord(
153171
NamedTuple("_NamedTuple", [("storage_id", int), ("asset_entry", AssetEntry)]),

0 commit comments

Comments
 (0)