Skip to content

Commit d6401a2

Browse files
abhizergz
authored andcommitted
py: add wait param to PipelineBuilder.create
Adds the parameter `wait` to PipelineBuilder.create, create_or_replace methods. `wait` determines if the function should way for the pipeline to compile after being created. True by default. Fixes: feldera#5018 Also updates the build-docs workflow to only build the feldera package instead of the entire feldera/python directory. Fixes: feldera#5019 Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
1 parent 31fcccd commit d6401a2

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

.github/workflows/build-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Build Python SDK docs
2121
working-directory: ./python/docs
2222
run: |
23-
uv run sphinx-apidoc -o . ../
23+
uv run sphinx-apidoc -o . ../feldera
2424
uv run sphinx-build -M html . _build
2525
2626
- name: Copy the Python docs to static

python/feldera/pipeline_builder.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
22
from typing import Optional
33

4+
from feldera.enums import CompilationProfile, PipelineFieldSelector
5+
from feldera.pipeline import Pipeline
6+
from feldera.rest.errors import FelderaAPIError
47
from feldera.rest.feldera_client import FelderaClient
58
from feldera.rest.pipeline import Pipeline as InnerPipeline
6-
from feldera.pipeline import Pipeline
7-
from feldera.enums import CompilationProfile, PipelineFieldSelector
89
from feldera.runtime_config import RuntimeConfig
9-
from feldera.rest.errors import FelderaAPIError
1010

1111

1212
class PipelineBuilder:
@@ -49,10 +49,11 @@ def __init__(
4949
"FELDERA_RUNTIME_VERSION", runtime_version
5050
)
5151

52-
def create(self) -> Pipeline:
52+
def create(self, wait: bool = True) -> Pipeline:
5353
"""
5454
Create the pipeline if it does not exist.
5555
56+
:param wait: Whether to wait for the pipeline to be created. True by default
5657
:return: The created pipeline
5758
"""
5859

@@ -82,17 +83,20 @@ def create(self) -> Pipeline:
8283
runtime_config=self.runtime_config.to_dict(),
8384
)
8485

85-
inner = self.client.create_pipeline(inner)
86+
inner = self.client.create_pipeline(inner, wait=wait)
8687
pipeline = Pipeline(self.client)
8788
pipeline._inner = inner
8889

8990
return pipeline
9091

91-
def create_or_replace(self) -> Pipeline:
92+
def create_or_replace(self, wait: bool = True) -> Pipeline:
9293
"""
9394
Creates a pipeline if it does not exist and replaces it if it exists.
9495
9596
If the pipeline exists and is running, it will be stopped and replaced.
97+
98+
:param wait: Whether to wait for the pipeline to be created. True by default
99+
:return: The created pipeline
96100
"""
97101

98102
if self.name is None or self.sql is None:
@@ -121,7 +125,7 @@ def create_or_replace(self) -> Pipeline:
121125
runtime_config=self.runtime_config.to_dict(),
122126
)
123127

124-
inner = self.client.create_or_update_pipeline(inner)
128+
inner = self.client.create_or_update_pipeline(inner, wait=wait)
125129
pipeline = Pipeline(self.client)
126130
pipeline._inner = inner
127131

python/feldera/rest/feldera_client.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import pathlib
2-
from typing import Any, Dict, Optional
1+
import json
32
import logging
3+
import pathlib
44
import time
5-
import json
65
from decimal import Decimal
7-
from typing import Generator, Mapping
6+
from typing import Any, Dict, Generator, Mapping, Optional
87
from urllib.parse import quote
8+
99
import requests
1010

1111
from feldera.enums import BootstrapPolicy, PipelineFieldSelector, PipelineStatus
12+
from feldera.rest._helpers import client_version
13+
from feldera.rest._httprequests import HttpRequests
1214
from feldera.rest.config import Config
15+
from feldera.rest.errors import FelderaAPIError, FelderaTimeoutError
1316
from feldera.rest.feldera_config import FelderaConfig
14-
from feldera.rest.errors import FelderaTimeoutError, FelderaAPIError
1517
from feldera.rest.pipeline import Pipeline
16-
from feldera.rest._httprequests import HttpRequests
17-
from feldera.rest._helpers import client_version
1818

1919

2020
def _validate_no_none_keys_in_map(data):
@@ -258,12 +258,12 @@ def __wait_for_pipeline_state_one_of(
258258
)
259259
time.sleep(0.1)
260260

261-
def create_pipeline(self, pipeline: Pipeline) -> Pipeline:
261+
def create_pipeline(self, pipeline: Pipeline, wait: bool = True) -> Pipeline:
262262
"""
263263
Create a pipeline if it doesn't exist and wait for it to compile
264264
265-
266-
:name: The name of the pipeline
265+
:param pipeline: The pipeline to create
266+
:param wait: Whether to wait for the pipeline to compile. True by default
267267
"""
268268

269269
body = {
@@ -281,12 +281,21 @@ def create_pipeline(self, pipeline: Pipeline) -> Pipeline:
281281
body=body,
282282
)
283283

284+
if not wait:
285+
return pipeline
286+
284287
return self.__wait_for_compilation(pipeline.name)
285288

286-
def create_or_update_pipeline(self, pipeline: Pipeline) -> Pipeline:
289+
def create_or_update_pipeline(
290+
self, pipeline: Pipeline, wait: bool = True
291+
) -> Pipeline:
287292
"""
288293
Create a pipeline if it doesn't exist or update a pipeline and wait for
289294
it to compile
295+
296+
:param pipeline: The pipeline to create or update
297+
:param wait: Whether to wait for the pipeline to compile. True by default
298+
:return: The created or updated pipeline
290299
"""
291300

292301
body = {
@@ -304,6 +313,9 @@ def create_or_update_pipeline(self, pipeline: Pipeline) -> Pipeline:
304313
body=body,
305314
)
306315

316+
if not wait:
317+
return pipeline
318+
307319
return self.__wait_for_compilation(pipeline.name)
308320

309321
def patch_pipeline(

0 commit comments

Comments
 (0)