Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(data-warehouse): external data job rewrite #21494

Merged
merged 30 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7ed7df3
WIP
Gilbert09 Apr 11, 2024
06bd71a
Reworked the worker to self-manage making schema schedules and use as…
Gilbert09 Apr 11, 2024
133ae43
Added schema status and use it for the job status
Gilbert09 Apr 12, 2024
973483f
Fixed existing tests
Gilbert09 Apr 12, 2024
6a4fc48
Added new tests to cover check_schedule_activity
Gilbert09 Apr 12, 2024
e92c9a0
Updated the source API to trigger active schemas
Gilbert09 Apr 12, 2024
d389cc7
Added master changes for stripe source
Gilbert09 Apr 12, 2024
4f528fc
Merge branch 'master' into tom/data-job-rewrite
Gilbert09 Apr 12, 2024
5106718
Updated mypy
Gilbert09 Apr 12, 2024
6e26830
add blank to field
EDsCODE Apr 12, 2024
37251b9
update migrations
EDsCODE Apr 15, 2024
c99e574
merge main
EDsCODE Apr 16, 2024
18d7547
update mypy
EDsCODE Apr 16, 2024
b7d60ac
fix tpyes
EDsCODE Apr 16, 2024
9d6d408
Update query snapshots
github-actions[bot] Apr 16, 2024
d5e6797
Update query snapshots
github-actions[bot] Apr 16, 2024
1af7773
fix types
EDsCODE Apr 16, 2024
3a283b1
update mypy
EDsCODE Apr 16, 2024
180f8ab
type ignore
EDsCODE Apr 17, 2024
b353b08
add comment
EDsCODE Apr 17, 2024
72d0114
merge main
EDsCODE Apr 17, 2024
1925606
add default args, fix missing schema sync creation, add deletion logic
EDsCODE Apr 17, 2024
45d0eda
remove defaults
EDsCODE Apr 17, 2024
1e8b4c5
add blank
EDsCODE Apr 17, 2024
b7e75dd
cleanup
EDsCODE Apr 17, 2024
ffd792e
Merge branch 'master' into tom/data-job-rewrite
EDsCODE Apr 17, 2024
0acf4e2
add failsafe
EDsCODE Apr 17, 2024
9df6108
update reload logic
EDsCODE Apr 17, 2024
9474a29
create new schemas if triggered between reloads
EDsCODE Apr 17, 2024
9c11a8c
add schema off check
EDsCODE Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion latest_migrations.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name
ee: 0016_rolemembership_organization_member
otp_static: 0002_throttling
otp_totp: 0002_auto_20190420_0723
posthog: 0400_datawarehousetable_row_count
posthog: 0401_externaldatajob_schema
sessions: 0001_initial
social_django: 0010_uid_db_index
two_factor: 0007_auto_20201201_1019
20 changes: 20 additions & 0 deletions posthog/migrations/0401_externaldatajob_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.13 on 2024-04-10 15:12

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("posthog", "0400_datawarehousetable_row_count"),
]

operations = [
migrations.AddField(
model_name="externaldatajob",
name="schema",
field=models.ForeignKey(
null=True, on_delete=django.db.models.deletion.CASCADE, to="posthog.externaldataschema"
),
),
]
13 changes: 13 additions & 0 deletions posthog/temporal/common/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@ async def sync_connect() -> Client:
settings.TEMPORAL_CLIENT_KEY,
)
return client


async def async_connect() -> Client:
"""Asynchronous connect to Temporal and return a Client."""
client = await connect(
settings.TEMPORAL_HOST,
settings.TEMPORAL_PORT,
settings.TEMPORAL_NAMESPACE,
settings.TEMPORAL_CLIENT_ROOT_CA,
settings.TEMPORAL_CLIENT_CERT,
settings.TEMPORAL_CLIENT_KEY,
)
return client
44 changes: 43 additions & 1 deletion posthog/temporal/common/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ async def create_schedule(temporal: Client, id: str, schedule: Schedule, trigger
)


async def a_create_schedule(temporal: Client, id: str, schedule: Schedule, trigger_immediately: bool = False):
"""Async create a Temporal Schedule."""
return await temporal.create_schedule(
id=id,
schedule=schedule,
trigger_immediately=trigger_immediately,
)


@async_to_sync
async def update_schedule(temporal: Client, id: str, schedule: Schedule) -> None:
"""Update a Temporal Schedule."""
Expand All @@ -25,6 +34,18 @@ async def updater(_: ScheduleUpdateInput) -> ScheduleUpdate:
)


async def a_update_schedule(temporal: Client, id: str, schedule: Schedule) -> None:
"""Async update a Temporal Schedule."""
handle = temporal.get_schedule_handle(id)

async def updater(_: ScheduleUpdateInput) -> ScheduleUpdate:
return ScheduleUpdate(schedule=schedule)

return await handle.update(
updater=updater,
)


@async_to_sync
async def unpause_schedule(temporal: Client, schedule_id: str, note: str | None = None) -> None:
"""Unpause a Temporal Schedule."""
Expand All @@ -39,6 +60,12 @@ async def delete_schedule(temporal: Client, schedule_id: str) -> None:
await handle.delete()


async def a_delete_schedule(temporal: Client, schedule_id: str) -> None:
"""Async delete a Temporal Schedule."""
handle = temporal.get_schedule_handle(schedule_id)
await handle.delete()


@async_to_sync
async def describe_schedule(temporal: Client, schedule_id: str):
"""Describe a Temporal Schedule."""
Expand All @@ -55,6 +82,21 @@ async def pause_schedule(temporal: Client, schedule_id: str, note: str | None =

@async_to_sync
async def trigger_schedule(temporal: Client, schedule_id: str, note: str | None = None) -> None:
"""Pause a Temporal Schedule."""
"""Trigger a Temporal Schedule."""
handle = temporal.get_schedule_handle(schedule_id)
await handle.trigger()


async def a_trigger_schedule(temporal: Client, schedule_id: str, note: str | None = None) -> None:
"""Trigger a Temporal Schedule."""
handle = temporal.get_schedule_handle(schedule_id)
await handle.trigger()


async def a_schedule_exists(temporal: Client, schedule_id: str) -> bool:
"""Check whether a schedule exists."""
try:
await temporal.get_schedule_handle(schedule_id).describe()
return True
except:
return False
10 changes: 6 additions & 4 deletions posthog/temporal/data_imports/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from posthog.temporal.data_imports.external_data_job import (
ExternalDataJobWorkflow,
create_external_data_job_model,
create_external_data_job_model_activity,
create_source_templates,
run_external_data_job,
import_data_activity,
update_external_data_job_model,
validate_schema_activity,
check_schedule_activity,
)

WORKFLOWS = [ExternalDataJobWorkflow]

ACTIVITIES = [
create_external_data_job_model,
create_external_data_job_model_activity,
update_external_data_job_model,
run_external_data_job,
import_data_activity,
validate_schema_activity,
create_source_templates,
check_schedule_activity,
]
Loading
Loading