:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-modeling): bump updated_at when job usage is recorded (#123113)
Jovan Sakovicf23bb34bf637
diff --git a/products/data_modeling/backend/test/test_job_usage.py b/products/data_modeling/backend/test/test_job_usage.pyindex 3331446027b7..8b35de03b6bc 100644--- a/products/data_modeling/backend/test/test_job_usage.py+++ b/products/data_modeling/backend/test/test_job_usage.py@@ -86,7 +86,9 @@ class TestJobUsageCollector(BaseTest):"read_bytes": 345,})- DataModelingJob.objects.filter(team=self.team).update(created_at=finished - timedelta(hours=1))+ DataModelingJob.objects.filter(team=self.team).update(+ created_at=finished - timedelta(hours=1), updated_at=finished - timedelta(hours=1)+ )bootstrap_client = MagicMock()bootstrap_client.execute.return_value = [("ops.example.com", 9000, 1, 1, "online", "ops")]cluster = ClickhouseCluster(bootstrap_client)@@ -108,6 +110,9 @@ class TestJobUsageCollector(BaseTest):(4096, 800, 2000, 4),)self.assertIsNotNone(measured.usage_updated_at)+ self.assertEqual(measured.updated_at, measured.usage_updated_at)+ assert measured.updated_at is not None+ self.assertGreater(measured.updated_at, finished - timedelta(hours=1))self.assertIsNone(missing.read_bytes)self.assertIsNone(duplicate.read_bytes)self.assertIsNone(duplicate.usage_updated_at)diff --git a/products/data_modeling/dags/job_usage.py b/products/data_modeling/dags/job_usage.pyindex 5f8c142a7e84..cc8996f020bf 100644--- a/products/data_modeling/dags/job_usage.py+++ b/products/data_modeling/dags/job_usage.py@@ -86,6 +86,7 @@ class JobUsageCollector:workload=Workload.DEFAULT,).result()updated: list[DataModelingJob] = []+ measured_at = datetime.now(UTC)for team_id, workflow_id, workflow_run_id, read_bytes, read_rows, cpu, query_count in rows:job = unique[(team_id, workflow_id, workflow_run_id)]job.read_bytes, job.read_rows, job.cpu_microseconds, job.query_count = (@@ -94,9 +95,10 @@ class JobUsageCollector:cpu,query_count,)- job.usage_updated_at = datetime.now(UTC)+ # bulk_update skips auto_now, and the warehouse mirror syncs rows by updated_at.+ job.usage_updated_at = job.updated_at = measured_atupdated.append(job)- DataModelingJob.objects.bulk_update(updated, USAGE_FIELDS, batch_size=BATCH_SIZE)+ DataModelingJob.objects.bulk_update(updated, [*USAGE_FIELDS, "updated_at"], batch_size=BATCH_SIZE)return CollectedJobUsage(measured_jobs=len(updated), ambiguous_jobs=ambiguous, expired_jobs=expired)@staticmethod