Skip to content

Commit

Permalink
fix: Also return records_total from HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias committed Mar 19, 2024
1 parent 063dc37 commit 855d9f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions posthog/temporal/batch_exports/http_batch_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def post_json_file_to_url(url, batch_file, session: aiohttp.ClientSession)


@activity.defn
async def insert_into_http_activity(inputs: HttpInsertInputs):
async def insert_into_http_activity(inputs: HttpInsertInputs) -> int:
"""Activity streams data from ClickHouse to an HTTP Endpoint."""
logger = await bind_temporal_worker_logger(team_id=inputs.team_id, destination="HTTP")
logger.info(
Expand Down Expand Up @@ -180,7 +180,7 @@ async def insert_into_http_activity(inputs: HttpInsertInputs):
inputs.data_interval_start,
inputs.data_interval_end,
)
return
return 0

logger.info("BatchExporting %s rows", count)

Expand Down Expand Up @@ -303,6 +303,8 @@ async def flush_batch_to_http_endpoint(last_uploaded_timestamp: str, session: ai
last_uploaded_timestamp = str(inserted_at)
await flush_batch_to_http_endpoint(last_uploaded_timestamp, session)

return batch_file.records_total


@workflow.defn(name="http-export")
class HttpBatchExportWorkflow(PostHogWorkflow):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def test_http_export_workflow(

run = runs[0]
assert run.status == "Completed"
assert run.records_completed == 100

await assert_clickhouse_records_in_mock_server(
mock_server=mock_server,
Expand Down Expand Up @@ -425,6 +426,7 @@ async def insert_into_http_activity_mocked(_: HttpInsertInputs) -> str:
run = runs[0]
assert run.status == "FailedRetryable"
assert run.latest_error == "ValueError: A useful error message"
assert run.records_completed == 0


async def test_http_export_workflow_handles_insert_activity_non_retryable_errors(ateam, http_batch_export, interval):
Expand Down

0 comments on commit 855d9f0

Please sign in to comment.