Skip to content

Commit

Permalink
update airbyte server block(s) script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishankoradia committed Dec 18, 2024
1 parent f36b58f commit dba8002
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ddpui/ddpprefect/prefect_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,16 @@ def create_airbyte_server_block(blockname):


def update_airbyte_server_block(blockname):
"""We don't update server blocks"""
raise Exception("not implemented")
"""Create airbyte server block in prefect"""
response = prefect_put(
"blocks/airbyte/server/",
{
"blockName": blockname,
"serverHost": os.getenv("AIRBYTE_SERVER_HOST"),
"serverPort": os.getenv("AIRBYTE_SERVER_PORT"),
},
)
return (response["block_id"], response["cleaned_block_name"])


def delete_airbyte_server_block(block_id):
Expand Down
33 changes: 33 additions & 0 deletions ddpui/management/commands/update_airbyte_server_blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.core.management.base import BaseCommand
from ddpui.models.org import Org, OrgPrefectBlockv1
from ddpui.ddpprefect import prefect_service


class Command(BaseCommand):
"""Update airbyte server blocks in prefect"""

help = "Update airbyte server blocks in prefect"

def add_arguments(self, parser):
"""adds command line arguments"""
parser.add_argument("org", type=str, help="Org slug, use 'all' to update for all orgs")

def handle(self, *args, **options):
"""Use airbyte host and port from the .env"""
orgs = Org.objects.all()
if options["org"] != "all":
orgs = orgs.filter(slug=options["org"])

print(f"Updating airbyte server blocks in prefect for {len(orgs)} orgs")

for org in orgs:
server_block = OrgPrefectBlockv1.objects.filter(org=org).first()

if not server_block:
print(f"Org {org.slug} does not have a server block")
continue

# update host and port
prefect_service.update_airbyte_server_block(server_block.block_name)

print(f"Updated airbyte server block for org {org.slug}")

0 comments on commit dba8002

Please sign in to comment.