Skip to content

: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.

feat(warehouse-sources): add zylo automations and executions tables (#113866)

Tom Owers509d5b8f45c2
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
index 66441ff799a0..bf4ee7f2da5a 100644
--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
@@ -1302,8 +1302,6 @@
1 products/warehouse_sources/backend/temporal/data_imports/sources/zoom/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/zoom/zoom.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/zuora/zuora.py
-1 products/warehouse_sources/backend/temporal/data_imports/sources/zylo/settings.py
-1 products/warehouse_sources/backend/temporal/data_imports/sources/zylo/zylo.py
1 products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_google_ads_source.py
1 products/warehouse_sources/backend/temporal/data_imports/workflow_activities/calculate_table_size.py
1 products/warehouse_sources/backend/temporal/data_imports/workflow_activities/check_billing_limits.py
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index fff00cf5055d..b0703cfb2329 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -9792,7 +9792,7 @@ Out of scope — the Metering/meters API (`/meters/*`): despite the "Metering/me
## Zylo — gaps
-Today (12): `ActivityHistory`, `ApplicationBudgets`, `ApplicationLicenses`, `ApplicationUsers`, `Applications`, `ContractLineItems`, `Contracts`, `POLineItems`, `Payments`, `PurchaseOrders`, `SavingsEvents`, `Suppliers`
+Today (14): `ActivityHistory`, `ApplicationBudgets`, `ApplicationLicenses`, `ApplicationUsers`, `Applications`, `AutomationExecutions`, `Automations`, `ContractLineItems`, `Contracts`, `POLineItems`, `Payments`, `PurchaseOrders`, `SavingsEvents`, `Suppliers`
Diffed against: <https://developer.zylo.com/sitemap.xml>
@@ -9808,5 +9808,7 @@ Diffed against: <https://developer.zylo.com/sitemap.xml>
- [ ] `/v2/applicationBudgets/stats` — budget-vs-actual aggregates alongside the raw ApplicationBudgets we already sync (medium)
- [ ] `/v2/workflows and /v2/workflows/{workflowId}/responses` — app-request and review workflow responses - per-response rows for governance reporting (low)
- [ ] `/v2/companyDocuments` — document metadata (MSAs, DPAs) linked to suppliers and contracts already synced (low)
+- [x] `/v2/automations` — automation configurations and their latest run status; needs a token with the automation role (`automations`)
+- [x] `/v2/automations/{automationId}/executions` — execution history per automation, fanned out over `/v2/automations`
-Note: Tables are static in products/warehouse_sources/backend/temporal/data_imports/sources/zylo/settings.py (ZYLO_ENDPOINTS), no dynamic discovery. Zylo does not publish a downloadable OpenAPI file - the docs are a ReadMe.io site - so I enumerated every operation from https://developer.zylo.com/sitemap.xml and confirmed each reported path by pulling the embedded operation JSON from the individual reference pages (e.g. https://developer.zylo.com/reference/userscontroller\_getusers yields "path":"/v2/users"). Deliberately excluded as config/plumbing: /v2/alerts, /v2/integrations, /v2/automations (+executions), /v2/company, payment upload jobs, and the reporting/query job endpoints. Note /v2/purchaseOrders is already flagged in-repo as scope-gated, so some of these may 403 for keys lacking spend:read.
+Note: Tables are static in products/warehouse_sources/backend/temporal/data_imports/sources/zylo/settings.py (ZYLO_ENDPOINTS), no dynamic discovery. Zylo does not publish a downloadable OpenAPI file - the docs are a ReadMe.io site - so I enumerated every operation from https://developer.zylo.com/sitemap.xml and confirmed each reported path by pulling the embedded operation JSON from the individual reference pages (e.g. https://developer.zylo.com/reference/userscontroller\_getusers yields "path":"/v2/users"). Deliberately excluded as config/plumbing: /v2/alerts, /v2/integrations, /v2/company, payment upload jobs, and the reporting/query job endpoints. Note /v2/purchaseOrders is already flagged in-repo as scope-gated, so some of these may 403 for keys lacking spend:read.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/canonical_descriptions.py
index cbbba0b521b5..e9cd279cb62a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/canonical_descriptions.py
@@ -230,4 +230,43 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
after="Value of the changed property after the event.",
),
},
+ "Automations": {
+ "description": "An automation configured in Zylo, with its trigger setup and latest run status.",
+ "docs_url": "https://developer.zylo.com/reference/automationscontroller_getautomations",
+ "columns": _columns(
+ id="Unique identifier for the automation.",
+ name="The name of the automation.",
+ state="Whether the automation is ACTIVE or INACTIVE.",
+ last_status="Status of the most recent execution (SUCCESS, ERROR, STOPPED, TIMED OUT, IN PROGRESS).",
+ last_run_time="Timestamp of the most recent execution.",
+ next_execution_time="The next scheduled execution time.",
+ run_count="Total number of times the automation has been executed.",
+ category_tags="Category tags assigned to the automation.",
+ triggers="Trigger configuration for the automation.",
+ created_by="The user who created the automation.",
+ modified_by="The user who last modified the automation.",
+ ),
+ },
+ "AutomationExecutions": {
+ "description": "A single run of a Zylo automation, with its outcome and message and ticket counts.",
+ "docs_url": "https://developer.zylo.com/reference/automationscontroller_getexecutions",
+ "columns": _columns(
+ id="Unique identifier for the execution.",
+ automation_id="ID of the automation that produced this execution.",
+ automation_name="Name of the automation that produced this execution.",
+ automation_state="Whether the parent automation is ACTIVE or INACTIVE.",
+ category_tags="Category tags assigned to the parent automation.",
+ status="Execution status (SUCCESS, ERROR, STOPPED, TIMED OUT, IN PROGRESS).",
+ trigger="Whether the execution was triggered On Demand or by a Schedule.",
+ start_time="When the execution started.",
+ stop_time="When the execution finished.",
+ error_cause="Root cause of the execution failure.",
+ messages_queued="Number of messages queued during the execution.",
+ messages_sent="Number of messages successfully sent.",
+ messages_errored="Number of messages that failed to send.",
+ tickets_created="Number of tickets created during the execution.",
+ tickets_errored="Number of tickets that failed to create.",
+ created_by="The user who triggered the execution.",
+ ),
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/settings.py
index 0ced1b1a557e..9708fa31674c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/settings.py
@@ -1,6 +1,9 @@
from dataclasses import dataclass, field
from typing import Optional
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+)
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
# Zylo Enterprise (v2) API base URL. Every endpoint path below is relative to this.
@@ -28,7 +31,7 @@ _SYSTEM_INCREMENTAL_FIELDS: list[IncrementalField] = [
]
-@dataclass
+@dataclass(frozen=True)
class ZyloEndpointConfig:
name: str
path: str
@@ -39,10 +42,23 @@ class ZyloEndpointConfig:
# Stable, never-updated datetime field used for partitioning. `zylo_created_at` is set once at
# record creation and never changes, unlike `zylo_modified_at`.
partition_key: Optional[str] = "zylo_created_at"
+ default_incremental_field: Optional[str] = "zylo_created_at"
+ page_size: int = PAGE_LIMIT
+ fanout: Optional[DependentEndpointConfig] = None
-# All resources are top-level list endpoints (no fan-out): every id in this catalog is a genuine
-# top-level list, so no parent identifier needs to ride in the primary key.
+# Executions are only listable per automation, so they fan out over `/v2/automations`. Execution
+# rows already carry `automation_id`, so nothing needs copying from the parent.
+AUTOMATION_FANOUT = DependentEndpointConfig(
+ parent_name="Automations",
+ resolve_param="automationId",
+ resolve_field="id",
+ include_from_parent=[],
+ parent_params={"sort": "+zylo_created_at"},
+)
+
+
+# Every resource except AutomationExecutions is a top-level list endpoint.
ZYLO_ENDPOINTS: dict[str, ZyloEndpointConfig] = {
"Applications": ZyloEndpointConfig(
name="Applications",
@@ -108,6 +124,20 @@ ZYLO_ENDPOINTS: dict[str, ZyloEndpointConfig] = {
path="/v2/activityHistory",
table_name="activity_history",
),
+ # Requires a token created with the automation role (`automations`).
+ "Automations": ZyloEndpointConfig(
+ name="Automations",
+ path="/v2/automations",
+ table_name="automations",
+ ),
+ # Execution ids are global (Zylo serves `/v2/automations/executions/{executionId}`), so `id`
+ # alone stays unique across every parent automation.
+ "AutomationExecutions": ZyloEndpointConfig(
+ name="AutomationExecutions",
+ path="/v2/automations/{automationId}/executions",
+ table_name="automation_executions",
+ fanout=AUTOMATION_FANOUT,
+ ),
}
ENDPOINTS = tuple(ZYLO_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/source.py
index d4d07653612d..65b2c1b7e268 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/source.py
@@ -41,6 +41,8 @@ _ENDPOINT_SCOPES: dict[str, str] = {
"SavingsEvents": "applications:read",
"ApplicationBudgets": "applications:read",
"ActivityHistory": "team:read",
+ "Automations": "automations",
+ "AutomationExecutions": "automations",
}
@@ -103,7 +105,13 @@ class ZyloSource(ResumableSource[ZyloSourceConfig, ZyloResumeConfig]):
if endpoint_config is None:
permissions[endpoint] = None
continue
- status = probe_endpoint_status(config.token_id, config.token_secret, endpoint_config.path)
+ # A fan-out child path has an unbound `{id}`, so probe its parent list, which needs the same scope.
+ probe_path = (
+ ZYLO_ENDPOINTS[endpoint_config.fanout.parent_name].path
+ if endpoint_config.fanout is not None
+ else endpoint_config.path
+ )
+ status = probe_endpoint_status(config.token_id, config.token_secret, probe_path)
# Only a real denial counts as missing scope — throttles, 5xx, and network blips
# must not mark a table unreachable.
if status == 403:
@@ -161,7 +169,8 @@ class ZyloSource(ResumableSource[ZyloSourceConfig, ZyloResumeConfig]):
"**Integrations → API Integration → Connect** in Zylo and paste the token ID and secret "
"below. The key needs read scopes (e.g. `applications:read`, `contracts:read`, "
"`spend:read`, `team:read`) for the resources you want to sync — Purchase Orders and PO "
- "Line Items are a premium feature and additionally require `spend:read`."
+ "Line Items are a premium feature and additionally require `spend:read`. Automations and "
+ "Automation Executions need a token created with the automation role (`automations`)."
),
iconPath="/static/services/zylo.png",
docsUrl="https://posthog.com/docs/cdp/sources/zylo",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo.py
index d308f188e5c4..875357e54741 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo.py
@@ -55,12 +55,16 @@ class TestZyloSourceResumeBehavior:
should_use_incremental_field: bool = False,
incremental_field: str | None = None,
db_incremental_field_last_value: Any = None,
+ sent_urls: list[str] | None = None,
+ rows: list[dict[str, Any]] | None = None,
) -> list[dict[str, Any]]:
sent_params: list[dict[str, Any]] = []
response_iter = iter(responses)
def fake_send(request: Any, *_args: Any, **_kwargs: Any) -> Response:
sent_params.append(dict(request.params or {}))
+ if sent_urls is not None:
+ sent_urls.append(request.url)
return next(response_iter)
with patch(
@@ -82,7 +86,9 @@ class TestZyloSourceResumeBehavior:
should_use_incremental_field=should_use_incremental_field,
incremental_field=incremental_field,
)
- list(cast(Iterable[Any], resource.items()))
+ for item in cast(Iterable[Any], resource.items()):
+ if rows is not None:
+ rows.extend(item if isinstance(item, list) else [item])
return sent_params
def test_fresh_run_saves_skip_after_each_non_terminal_page(self) -> None:
@@ -139,6 +145,67 @@ class TestZyloSourceResumeBehavior:
assert sent_params[0]["zylo_created_at"] == f"{INITIAL_INCREMENTAL_VALUE},gte"
assert sent_params[0]["sort"] == "+zylo_created_at"
+ def test_executions_fan_out_per_automation_with_incremental_filter(self) -> None:
+ manager = MagicMock(spec=ResumableSourceManager)
+ manager.can_resume.return_value = False
+
+ responses = [
+ _make_http_response([{"id": "auto_1"}, {"id": "auto_2"}]),
+ _make_http_response([{"id": f"exec_{i}", "automation_id": "auto_1"} for i in range(1000)]),
+ _make_http_response([{"id": "exec_last", "automation_id": "auto_1"}]),
+ _make_http_response([{"id": "exec_b", "automation_id": "auto_2"}]),
+ ]
+ sent_urls: list[str] = []
+ rows: list[dict[str, Any]] = []
+ sent_params = self._drive(
+ "AutomationExecutions",
+ manager,
+ responses,
+ should_use_incremental_field=True,
+ incremental_field="zylo_modified_at",
+ db_incremental_field_last_value=datetime(2026, 7, 21, 12, tzinfo=UTC),
+ sent_urls=sent_urls,
+ rows=rows,
+ )
+
+ assert [url.removeprefix("https://api.zylo.com") for url in sent_urls] == [
+ "/v2/automations",
+ "/v2/automations/auto_1/executions",
+ "/v2/automations/auto_1/executions",
+ "/v2/automations/auto_2/executions",
+ ]
+ assert "zylo_modified_at" not in sent_params[0]
+ assert [p.get("skip") for p in sent_params[1:]] == [0, 1000, 0]
+ for child_params in sent_params[1:]:
+ assert child_params["zylo_modified_at"] == "2026-07-21,gte"
+ assert child_params["sort"] == "+zylo_modified_at"
+ assert len(rows) == 1002
+
+ def test_executions_resume_skips_completed_automations(self) -> None:
+ manager = MagicMock(spec=ResumableSourceManager)
+ manager.can_resume.return_value = True
+ manager.load_state.return_value = ZyloResumeConfig(
+ fanout_state={"completed": ["/v2/automations/auto_1/executions"], "current": None, "child_state": None}
+ )
+
+ responses = [
+ _make_http_response([{"id": "auto_1"}, {"id": "auto_2"}]),
+ _make_http_response([{"id": "exec_b", "automation_id": "auto_2"}]),
+ ]
+ sent_urls: list[str] = []
+ self._drive("AutomationExecutions", manager, responses, sent_urls=sent_urls)
+
+ assert [url.removeprefix("https://api.zylo.com") for url in sent_urls] == [
+ "/v2/automations",
+ "/v2/automations/auto_2/executions",
+ ]
+ saved = manager.save_state.call_args_list[-1].args[0]
+ assert saved.next_skip is None
+ assert set(saved.fanout_state["completed"]) == {
+ "/v2/automations/auto_1/executions",
+ "/v2/automations/auto_2/executions",
+ }
+
class TestValidateCredentials:
@pytest.mark.parametrize(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo_source.py
index 595c7ed8f1e4..34cd42dbfa79 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/tests/test_zylo_source.py
@@ -70,6 +70,15 @@ class TestZyloSource:
assert permissions == {"PurchaseOrders": expected_message}
+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.zylo.source.probe_endpoint_status")
+ def test_get_endpoint_permissions_probes_fanout_child_via_parent_list(self, mock_probe: MagicMock) -> None:
+ mock_probe.return_value = 403
+
+ permissions = self.source.get_endpoint_permissions(self.config, self.team_id, ["AutomationExecutions"])
+
+ assert permissions == {"AutomationExecutions": "API key is missing the `automations` permission scope"}
+ mock_probe.assert_called_once_with("tok_id", "tok_secret", "/v2/automations")
+
def test_get_endpoint_permissions_unknown_endpoint_is_reachable(self) -> None:
permissions = self.source.get_endpoint_permissions(self.config, self.team_id, ["NotARealEndpoint"])
assert permissions == {"NotARealEndpoint": None}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/zylo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/zylo.py
index bbb4419a747f..2587dea33b3c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/zylo.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/zylo/zylo.py
@@ -1,4 +1,5 @@
import dataclasses
+from collections.abc import Callable, Iterable
from datetime import date, datetime
from typing import Any, Optional
@@ -9,12 +10,17 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
RESTAPIConfig,
rest_api_resource,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ build_dependent_resource,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
OffsetPaginator,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
+ ClientConfig,
Endpoint,
EndpointResource,
+ IncrementalConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
@@ -30,9 +36,12 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.zylo.setti
INITIAL_INCREMENTAL_VALUE = "1970-01-01"
[email protected](frozen=True)
class ZyloResumeConfig:
- next_skip: int
+ next_skip: Optional[int] = None
+ # AutomationExecutions fans out over Automations, so its resume state is the shape
+ # `build_dependent_resource` checkpoints: finished parents and where the current one stopped.
+ fanout_state: Optional[dict[str, Any]] = None
def _format_zylo_filter_date(value: Any) -> str:
@@ -55,6 +64,25 @@ def _format_zylo_filter_date(value: Any) -> str:
return f"{d.isoformat()},gte"
+def _resolve_cursor(
+ config: ZyloEndpointConfig, should_use_incremental_field: bool, incremental_field: Optional[str]
+) -> Optional[str]:
+ if not (should_use_incremental_field and config.incremental_fields):
+ return None
+ # Honor the user's chosen cursor field; fall back to the first advertised option.
+ advertised = {f["field"] for f in config.incremental_fields}
+ return incremental_field if incremental_field in advertised else config.incremental_fields[0]["field"]
+
+
+def _incremental_config(cursor: str) -> IncrementalConfig:
+ return {
+ "cursor_path": cursor,
+ "start_param": cursor,
+ "initial_value": INITIAL_INCREMENTAL_VALUE,
+ "convert": _format_zylo_filter_date,
+ }
+
+
def get_resource(
endpoint: str,
should_use_incremental_field: bool,
@@ -62,19 +90,14 @@ def get_resource(
) -> EndpointResource:
config: ZyloEndpointConfig = ZYLO_ENDPOINTS[endpoint]
- is_incremental = should_use_incremental_field and bool(config.incremental_fields)
-
- cursor: Optional[str] = None
- if is_incremental:
- # Honor the user's chosen cursor field; fall back to the first advertised option.
- advertised = {f["field"] for f in config.incremental_fields}
- cursor = incremental_field if incremental_field in advertised else config.incremental_fields[0]["field"]
+ cursor = _resolve_cursor(config, should_use_incremental_field, incremental_field)
+ is_incremental = cursor is not None
sort_field = cursor or "zylo_created_at"
params: dict[str, Any] = {
"sort": f"+{sort_field}",
}
- if is_incremental and cursor is not None:
+ if cursor is not None:
params[cursor] = {
"type": "incremental",
"cursor_path": cursor,
@@ -108,20 +131,52 @@ def zylo_source(
should_use_incremental_field: bool = False,
incremental_field: Optional[str] = None,
) -> SourceResponse:
- config: RESTAPIConfig = {
- "client": {
- "base_url": ZYLO_BASE_URL,
- "auth": {
- "type": "bearer",
- "token": f"{token_id}:{token_secret}",
- },
- "paginator": OffsetPaginator(
- limit=PAGE_LIMIT,
- offset_param="skip",
- limit_param="limit",
- total_path=None,
- ),
+ endpoint_config = ZYLO_ENDPOINTS[endpoint]
+ client_config: ClientConfig = {
+ "base_url": ZYLO_BASE_URL,
+ "auth": {
+ "type": "bearer",
+ "token": f"{token_id}:{token_secret}",
},
+ "paginator": OffsetPaginator(
+ limit=PAGE_LIMIT,
+ offset_param="skip",
+ limit_param="limit",
+ total_path=None,
+ ),
+ }
+
+ resume_config = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None
+
+ if endpoint_config.fanout is not None:
+ cursor = _resolve_cursor(endpoint_config, should_use_incremental_field, incremental_field)
+
+ def save_fanout_checkpoint(state: Optional[dict[str, Any]]) -> None:
+ if state:
+ resumable_source_manager.save_state(ZyloResumeConfig(fanout_state=state))
+
+ child = build_dependent_resource(
+ endpoint_configs=ZYLO_ENDPOINTS,
+ child_endpoint=endpoint,
+ fanout=endpoint_config.fanout,
+ client_config=client_config,
+ path_format_values={},
+ team_id=team_id,
+ job_id=job_id,
+ db_incremental_field_last_value=db_incremental_field_last_value,
+ should_use_incremental_field=should_use_incremental_field,
+ incremental_field=cursor,
+ incremental_config_factory=_incremental_config,
+ child_params_extra={"sort": f"+{cursor or 'zylo_created_at'}"},
+ # The client's OffsetPaginator already sends `limit`.
+ page_size_param=None,
+ resume_hook=save_fanout_checkpoint,
+ initial_paginator_state=resume_config.fanout_state if resume_config else None,
+ )
+ return _make_source_response(endpoint_config, lambda: child)
+
+ config: RESTAPIConfig = {
+ "client": client_config,
# Write disposition is set per-resource in get_resource (it always wins over
# resource_defaults), so no default is needed here.
"resource_defaults": {},
@@ -129,10 +184,8 @@ def zylo_source(
}
initial_paginator_state: Optional[dict[str, Any]] = None
- if resumable_source_manager.can_resume():
- resume_config = resumable_source_manager.load_state()
- if resume_config is not None:
- initial_paginator_state = {"offset": resume_config.next_skip}
+ if resume_config is not None and resume_config.next_skip is not None:
+ initial_paginator_state = {"offset": resume_config.next_skip}
def save_checkpoint(state: Optional[dict[str, Any]]) -> None:
# Persist only when there's a next page to resume to. Redis TTL handles cleanup on completion.
@@ -148,11 +201,13 @@ def zylo_source(
initial_paginator_state=initial_paginator_state,
)
- endpoint_config = ZYLO_ENDPOINTS[endpoint]
+ return _make_source_response(endpoint_config, lambda: resource)
+
+def _make_source_response(endpoint_config: ZyloEndpointConfig, items: Callable[[], Iterable[Any]]) -> SourceResponse:
return SourceResponse(
- name=endpoint,
- items=lambda: resource,
+ name=endpoint_config.name,
+ items=items,
primary_keys=endpoint_config.primary_keys,
partition_count=1,
partition_size=1,