-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d012f7
commit 22634f0
Showing
43 changed files
with
2,665 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 4.2.15 on 2024-12-16 11:55 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import posthog.helpers.encrypted_fields | ||
import posthog.models.utils | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("posthog", "0550_migrate_action_webhooks_to_destinations"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="BatchImport", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=posthog.models.utils.UUIDT, editable=False, primary_key=True, serialize=False | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("lease_id", models.TextField(blank=True, null=True)), | ||
("leased_until", models.DateTimeField(blank=True, null=True)), | ||
( | ||
"status", | ||
models.TextField( | ||
choices=[ | ||
("completed", "Completed"), | ||
("failed", "Failed"), | ||
("paused", "Paused"), | ||
("running", "Running"), | ||
], | ||
default="running", | ||
), | ||
), | ||
("status_message", models.TextField(blank=True, null=True)), | ||
("state", models.JSONField(blank=True, null=True)), | ||
("import_config", models.JSONField()), | ||
("secrets", posthog.helpers.encrypted_fields.EncryptedJSONStringField()), | ||
("team", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.team")), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0550_migrate_action_webhooks_to_destinations | ||
0551_batchimport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from django.db import models | ||
|
||
from posthog.models.utils import UUIDModel | ||
from posthog.models.team import Team | ||
|
||
from posthog.helpers.encrypted_fields import EncryptedJSONStringField | ||
|
||
from typing import Self | ||
from enum import Enum | ||
|
||
|
||
class ContentType(str, Enum): | ||
MIXPANEL = "mixpanel" | ||
CAPTURED = "captured" | ||
|
||
def serialize(self) -> dict: | ||
return {"type": self.value} | ||
|
||
|
||
class BatchImport(UUIDModel): | ||
class Status(models.TextChoices): | ||
COMPLETED = "completed", "Completed" | ||
FAILED = "failed", "Failed" | ||
PAUSED = "paused", "Paused" | ||
RUNNING = "running", "Running" | ||
|
||
team = models.ForeignKey(Team, on_delete=models.CASCADE) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
lease_id = models.TextField(null=True, blank=True) | ||
leased_until = models.DateTimeField(null=True, blank=True) | ||
status = models.TextField(choices=Status.choices, default=Status.RUNNING) | ||
status_message = models.TextField(null=True, blank=True) | ||
state = models.JSONField(null=True, blank=True) | ||
import_config = models.JSONField() | ||
secrets = EncryptedJSONStringField() | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._config_builder = BatchImportConfigBuilder(self) | ||
|
||
@property | ||
def config(self) -> "BatchImportConfigBuilder": | ||
return self._config_builder | ||
|
||
|
||
# Mostly used for manual job creation | ||
class BatchImportConfigBuilder: | ||
def __init__(self, batch_import: BatchImport): | ||
self.batch_import = batch_import | ||
self.batch_import.import_config = {} | ||
self.batch_import.secrets = {} | ||
|
||
def json_lines(self, content_type: ContentType, skip_blanks: bool = True) -> Self: | ||
self.batch_import.import_config["data_format"] = { | ||
"type": "json_lines", | ||
"skip_blanks": skip_blanks, | ||
"content": content_type.serialize(), | ||
} | ||
return self | ||
|
||
def from_folder(self, path: str) -> Self: | ||
self.batch_import.import_config["source"] = {"type": "folder", "path": path} | ||
return self | ||
|
||
def from_urls( | ||
self, urls: list[str], urls_key: str = "urls", allow_internal_ips: bool = False, timeout_seconds: int = 30 | ||
) -> Self: | ||
self.batch_import.import_config["source"] = { | ||
"type": "url_list", | ||
"urls_key": urls_key, | ||
"allow_internal_ips": allow_internal_ips, | ||
"timeout_seconds": timeout_seconds, | ||
} | ||
self.batch_import.secrets[urls_key] = urls | ||
return self | ||
|
||
def to_stdout(self, as_json: bool = True) -> Self: | ||
self.batch_import.import_config["sink"] = {"type": "stdout", "as_json": as_json} | ||
return self | ||
|
||
def to_file(self, path: str, as_json: bool = True, cleanup: bool = False) -> Self: | ||
self.batch_import.import_config["sink"] = {"type": "file", "path": path, "as_json": as_json, "cleanup": cleanup} | ||
return self | ||
|
||
def to_kafka(self, topic: str, send_rate: int, transaction_timeout_seconds: int) -> Self: | ||
self.batch_import.import_config["sink"] = { | ||
"type": "kafka", | ||
"topic": topic, | ||
"send_rate": send_rate, | ||
"transaction_timeout_seconds": transaction_timeout_seconds, | ||
} | ||
return self |
68 changes: 68 additions & 0 deletions
68
rust/.sqlx/query-0f547fc3a70bfd5b11b804dc971fc4944a76de2997b1fd077d25a5d3fdc6029b.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
rust/.sqlx/query-1f55549e1c3e14f539594ba9554fe53a98e367556b6e62681410e4786f6777f6.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
rust/.sqlx/query-ace06e5c2b903628287dad09cf2ed811a5c261c94b9440b8faccf026597f9cd0.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
rust/.sqlx/query-c9d960277e49c289bcb6d682d3d30bb226c060fde9f24eea420f77ab3ec62a9f.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.