From 732a84ad37f27a742f3c2d8c9f927f683473c1d1 Mon Sep 17 00:00:00 2001 From: marcosschroh Date: Thu, 4 Jul 2024 13:29:50 +0000 Subject: [PATCH] deploy: 91480525b615ce3f4fc6489234fb76cd4c404839 --- engine/index.html | 870 +++++++++++++++++++++++++++++++++++++++++++++- objects.inv | Bin 518 -> 542 bytes sitemap.xml.gz | Bin 127 -> 127 bytes utils/index.html | 12 +- 4 files changed, 865 insertions(+), 17 deletions(-) diff --git a/engine/index.html b/engine/index.html index 68764b8f..3720e8fb 100644 --- a/engine/index.html +++ b/engine/index.html @@ -282,6 +282,34 @@ send() + + +
  • + + on_startup() + + +
  • + +
  • + + on_stop() + + +
  • + +
  • + + after_startup() + + +
  • + +
  • + + after_stop() + +
  • @@ -456,6 +484,34 @@ send() + + +
  • + + on_startup() + + +
  • + +
  • + + on_stop() + + +
  • + +
  • + + after_startup() + + +
  • + +
  • + + after_stop() + +
  • @@ -852,7 +908,151 @@

    256 257 258 -259
    class StreamEngine:
    +259
    +260
    +261
    +262
    +263
    +264
    +265
    +266
    +267
    +268
    +269
    +270
    +271
    +272
    +273
    +274
    +275
    +276
    +277
    +278
    +279
    +280
    +281
    +282
    +283
    +284
    +285
    +286
    +287
    +288
    +289
    +290
    +291
    +292
    +293
    +294
    +295
    +296
    +297
    +298
    +299
    +300
    +301
    +302
    +303
    +304
    +305
    +306
    +307
    +308
    +309
    +310
    +311
    +312
    +313
    +314
    +315
    +316
    +317
    +318
    +319
    +320
    +321
    +322
    +323
    +324
    +325
    +326
    +327
    +328
    +329
    +330
    +331
    +332
    +333
    +334
    +335
    +336
    +337
    +338
    +339
    +340
    +341
    +342
    +343
    +344
    +345
    +346
    +347
    +348
    +349
    +350
    +351
    +352
    +353
    +354
    +355
    +356
    +357
    +358
    +359
    +360
    +361
    +362
    +363
    +364
    +365
    +366
    +367
    +368
    +369
    +370
    +371
    +372
    +373
    +374
    +375
    +376
    +377
    +378
    +379
    +380
    +381
    +382
    +383
    +384
    +385
    +386
    +387
    +388
    +389
    +390
    +391
    +392
    +393
    +394
    +395
    +396
    +397
    +398
    +399
    +400
    +401
    +402
    +403
    class StreamEngine:
         """
         Attributes:
             backend kstreams.backends.Kafka: Backend to connect. Default `Kafka`
    @@ -897,6 +1097,10 @@ 

    title: typing.Optional[str] = None, deserializer: typing.Optional[Deserializer] = None, serializer: typing.Optional[Serializer] = None, + on_startup: typing.Optional[EngineHooks] = None, + on_stop: typing.Optional[EngineHooks] = None, + after_startup: typing.Optional[EngineHooks] = None, + after_stop: typing.Optional[EngineHooks] = None, ) -> None: self.title = title self.backend = backend @@ -907,6 +1111,10 @@

    self.monitor = monitor self._producer: typing.Optional[typing.Type[Producer]] = None self._streams: typing.List[Stream] = [] + self._on_startup = [] if on_startup is None else list(on_startup) + self._on_stop = [] if on_stop is None else list(on_stop) + self._after_startup = [] if after_startup is None else list(after_startup) + self._after_stop = [] if after_stop is None else list(after_stop) async def send( self, @@ -962,6 +1170,9 @@

    return metadata async def start(self) -> None: + # Execute on_startup hooks + await execute_hooks(self._on_startup) + # add the producer and streams to the Monitor self.monitor.add_producer(self._producer) self.monitor.add_streams(self._streams) @@ -969,11 +1180,144 @@

    await self.start_producer() await self.start_streams() + # Execute after_startup hooks + await execute_hooks(self._after_startup) + + def on_startup( + self, + func: typing.Callable[[], typing.Any], + ) -> typing.Callable[[], typing.Any]: + """ + A list of callables to run before the engine starts. + Handler are callables that do not take any arguments, and may be either + standard functions, or async functions. + + Attributes: + func typing.Callable[[], typing.Any]: Func to callable before engine starts + + !!! Example + ```python title="Engine before startup" + + import kstreams + + stream_engine = kstreams.create_engine( + title="my-stream-engine" + ) + + @stream_engine.on_startup + async def init_db() -> None: + print("Initializing Database Connections") + await init_db() + + + @stream_engine.on_startup + async def start_background_task() -> None: + print("Some background task") + ``` + """ + self._on_startup.append(func) + return func + + def on_stop( + self, + func: typing.Callable[[], typing.Any], + ) -> typing.Callable[[], typing.Any]: + """ + A list of callables to run before the engine stops. + Handler are callables that do not take any arguments, and may be either + standard functions, or async functions. + + Attributes: + func typing.Callable[[], typing.Any]: Func to callable before engine stops + + !!! Example + ```python title="Engine before stops" + + import kstreams + + stream_engine = kstreams.create_engine( + title="my-stream-engine" + ) + + @stream_engine.on_stop + async def close_db() -> None: + print("Closing Database Connections") + await db_close() + ``` + """ + self._on_stop.append(func) + return func + + def after_startup( + self, + func: typing.Callable[[], typing.Any], + ) -> typing.Callable[[], typing.Any]: + """ + A list of callables to run after the engine starts. + Handler are callables that do not take any arguments, and may be either + standard functions, or async functions. + + Attributes: + func typing.Callable[[], typing.Any]: Func to callable after engine starts + + !!! Example + ```python title="Engine after startup" + + import kstreams + + stream_engine = kstreams.create_engine( + title="my-stream-engine" + ) + + @stream_engine.after_startup + async def after_startup() -> None: + print("Set pod as healthy") + await mark_healthy_pod() + ``` + """ + self._after_startup.append(func) + return func + + def after_stop( + self, + func: typing.Callable[[], typing.Any], + ) -> typing.Callable[[], typing.Any]: + """ + A list of callables to run after the engine stops. + Handler are callables that do not take any arguments, and may be either + standard functions, or async functions. + + Attributes: + func typing.Callable[[], typing.Any]: Func to callable after engine stops + + !!! Example + ```python title="Engine after stops" + + import kstreams + + stream_engine = kstreams.create_engine( + title="my-stream-engine" + ) + + @stream_engine.after_stop + async def after_stop() -> None: + print("Finishing backgrpund tasks") + ``` + """ + self._after_stop.append(func) + return func + async def stop(self) -> None: + # Execute on_startup hooks + await execute_hooks(self._on_stop) + await self.monitor.stop() await self.stop_producer() await self.stop_streams() + # Execute after_startup hooks + await execute_hooks(self._after_stop) + async def stop_producer(self): if self._producer is not None: await self._producer.stop() @@ -1226,15 +1570,7 @@

    Source code in kstreams/engine.py -
     82
    - 83
    - 84
    - 85
    - 86
    - 87
    - 88
    - 89
    - 90
    +            
     90
      91
      92
      93
    @@ -1277,7 +1613,15 @@ 

    130 131 132 -133

    async def send(
    +133
    +134
    +135
    +136
    +137
    +138
    +139
    +140
    +141
    async def send(
         self,
         topic: str,
         value: typing.Any = None,
    @@ -1336,6 +1680,510 @@ 

    +
    + + + + +

    + on_startup(func) + +

    + + +
    + +

    A list of callables to run before the engine starts. +Handler are callables that do not take any arguments, and may be either +standard functions, or async functions.

    + + + +

    Attributes:

    + + + + + + + + + + + + + + + +
    NameTypeDescription
    func + Callable[[], Any] + +
    +

    Func to callable before engine starts

    +
    +
    +
    +

    Example

    +
    Engine before startup
    import kstreams
    +
    +stream_engine = kstreams.create_engine(
    +    title="my-stream-engine"
    +)
    +
    +@stream_engine.on_startup
    +async def init_db() -> None:
    +    print("Initializing Database Connections")
    +    await init_db()
    +
    +
    +@stream_engine.on_startup
    +async def start_background_task() -> None:
    +    print("Some background task")
    +
    +
    + +
    + Source code in kstreams/engine.py +
    157
    +158
    +159
    +160
    +161
    +162
    +163
    +164
    +165
    +166
    +167
    +168
    +169
    +170
    +171
    +172
    +173
    +174
    +175
    +176
    +177
    +178
    +179
    +180
    +181
    +182
    +183
    +184
    +185
    +186
    +187
    +188
    +189
    +190
    def on_startup(
    +    self,
    +    func: typing.Callable[[], typing.Any],
    +) -> typing.Callable[[], typing.Any]:
    +    """
    +    A list of callables to run before the engine starts.
    +    Handler are callables that do not take any arguments, and may be either
    +    standard functions, or async functions.
    +
    +    Attributes:
    +        func typing.Callable[[], typing.Any]: Func to callable before engine starts
    +
    +    !!! Example
    +        ```python title="Engine before startup"
    +
    +        import kstreams
    +
    +        stream_engine = kstreams.create_engine(
    +            title="my-stream-engine"
    +        )
    +
    +        @stream_engine.on_startup
    +        async def init_db() -> None:
    +            print("Initializing Database Connections")
    +            await init_db()
    +
    +
    +        @stream_engine.on_startup
    +        async def start_background_task() -> None:
    +            print("Some background task")
    +        ```
    +    """
    +    self._on_startup.append(func)
    +    return func
    +
    +
    +
    + +
    + + +
    + + + + +

    + on_stop(func) + +

    + + +
    + +

    A list of callables to run before the engine stops. +Handler are callables that do not take any arguments, and may be either +standard functions, or async functions.

    + + + +

    Attributes:

    + + + + + + + + + + + + + + + +
    NameTypeDescription
    func + Callable[[], Any] + +
    +

    Func to callable before engine stops

    +
    +
    +
    +

    Example

    +
    Engine before stops
    import kstreams
    +
    +stream_engine = kstreams.create_engine(
    +    title="my-stream-engine"
    +)
    +
    +@stream_engine.on_stop
    +async def close_db() -> None:
    +    print("Closing Database Connections")
    +    await db_close()
    +
    +
    + +
    + Source code in kstreams/engine.py +
    192
    +193
    +194
    +195
    +196
    +197
    +198
    +199
    +200
    +201
    +202
    +203
    +204
    +205
    +206
    +207
    +208
    +209
    +210
    +211
    +212
    +213
    +214
    +215
    +216
    +217
    +218
    +219
    +220
    def on_stop(
    +    self,
    +    func: typing.Callable[[], typing.Any],
    +) -> typing.Callable[[], typing.Any]:
    +    """
    +    A list of callables to run before the engine stops.
    +    Handler are callables that do not take any arguments, and may be either
    +    standard functions, or async functions.
    +
    +    Attributes:
    +        func typing.Callable[[], typing.Any]: Func to callable before engine stops
    +
    +    !!! Example
    +        ```python title="Engine before stops"
    +
    +        import kstreams
    +
    +        stream_engine = kstreams.create_engine(
    +            title="my-stream-engine"
    +        )
    +
    +        @stream_engine.on_stop
    +        async def close_db() -> None:
    +            print("Closing Database Connections")
    +            await db_close()
    +        ```
    +    """
    +    self._on_stop.append(func)
    +    return func
    +
    +
    +
    + +
    + + +
    + + + + +

    + after_startup(func) + +

    + + +
    + +

    A list of callables to run after the engine starts. +Handler are callables that do not take any arguments, and may be either +standard functions, or async functions.

    + + + +

    Attributes:

    + + + + + + + + + + + + + + + +
    NameTypeDescription
    func + Callable[[], Any] + +
    +

    Func to callable after engine starts

    +
    +
    +
    +

    Example

    +
    Engine after startup
    import kstreams
    +
    +stream_engine = kstreams.create_engine(
    +    title="my-stream-engine"
    +)
    +
    +@stream_engine.after_startup
    +async def after_startup() -> None:
    +    print("Set pod as healthy")
    +    await mark_healthy_pod()
    +
    +
    + +
    + Source code in kstreams/engine.py +
    222
    +223
    +224
    +225
    +226
    +227
    +228
    +229
    +230
    +231
    +232
    +233
    +234
    +235
    +236
    +237
    +238
    +239
    +240
    +241
    +242
    +243
    +244
    +245
    +246
    +247
    +248
    +249
    +250
    def after_startup(
    +    self,
    +    func: typing.Callable[[], typing.Any],
    +) -> typing.Callable[[], typing.Any]:
    +    """
    +    A list of callables to run after the engine starts.
    +    Handler are callables that do not take any arguments, and may be either
    +    standard functions, or async functions.
    +
    +    Attributes:
    +        func typing.Callable[[], typing.Any]: Func to callable after engine starts
    +
    +    !!! Example
    +        ```python title="Engine after startup"
    +
    +        import kstreams
    +
    +        stream_engine = kstreams.create_engine(
    +            title="my-stream-engine"
    +        )
    +
    +        @stream_engine.after_startup
    +        async def after_startup() -> None:
    +            print("Set pod as healthy")
    +            await mark_healthy_pod()
    +        ```
    +    """
    +    self._after_startup.append(func)
    +    return func
    +
    +
    +
    + +
    + + +
    + + + + +

    + after_stop(func) + +

    + + +
    + +

    A list of callables to run after the engine stops. +Handler are callables that do not take any arguments, and may be either +standard functions, or async functions.

    + + + +

    Attributes:

    + + + + + + + + + + + + + + + +
    NameTypeDescription
    func + Callable[[], Any] + +
    +

    Func to callable after engine stops

    +
    +
    +
    +

    Example

    +
    Engine after stops
    import kstreams
    +
    +stream_engine = kstreams.create_engine(
    +    title="my-stream-engine"
    +)
    +
    +@stream_engine.after_stop
    +async def after_stop() -> None:
    +    print("Finishing backgrpund tasks")
    +
    +
    + +
    + Source code in kstreams/engine.py +
    252
    +253
    +254
    +255
    +256
    +257
    +258
    +259
    +260
    +261
    +262
    +263
    +264
    +265
    +266
    +267
    +268
    +269
    +270
    +271
    +272
    +273
    +274
    +275
    +276
    +277
    +278
    +279
    def after_stop(
    +    self,
    +    func: typing.Callable[[], typing.Any],
    +) -> typing.Callable[[], typing.Any]:
    +    """
    +    A list of callables to run after the engine stops.
    +    Handler are callables that do not take any arguments, and may be either
    +    standard functions, or async functions.
    +
    +    Attributes:
    +        func typing.Callable[[], typing.Any]: Func to callable after engine stops
    +
    +    !!! Example
    +        ```python title="Engine after stops"
    +
    +        import kstreams
    +
    +        stream_engine = kstreams.create_engine(
    +            title="my-stream-engine"
    +        )
    +
    +        @stream_engine.after_stop
    +        async def after_stop() -> None:
    +            print("Finishing backgrpund tasks")
    +        ```
    +    """
    +    self._after_stop.append(func)
    +    return func
    +
    +
    +
    + +
    + + diff --git a/objects.inv b/objects.inv index 47698c4c441be3ed4bf206df9fb9d2819ebd43e1..63de2e3519f99c51204d9bf80cbd518518710035 100644 GIT binary patch delta 427 zcmV;c0aX5m1fB$teSb}F!Y~ZI?^hsgS2FFo+r&6+NYnTMl}TL|H6K;%GT5(QS|}|Q zg|={M6Wj0k#ZH_Odjvyb1u{h&lSm;+L3|Y7Nw#~H8i*z@lgj`6_%xY5q!kS9T3Hm! zayu_KP1N3f9U~}k7r-R9l9jVVu+B!r;5pB3VsNA3kTCjNHGfnj{bU#w#~OdZV{^GU zF2B5EC!KCKqYmsvHs4Cj3Jo>uB{tlG$uyFPfuRgSn!?6Al0Rr*dhj>hQSFW@cTG#; zEx6y2&@0gD5B)$P(%D4kX!)4?XgQm1R(b0@&FsBO8R~A3e=w(ovx?m*YHw0@eGMhn zXwd^>6eLq_!hg*O0bWUJU5-x5S~rR1*)voTP*C+k*XEXrzEoZ19D^4zj*@fu@88~u zh|+Q~JhX)k*j+o{IpkvBuWwv|1}pJX5f@Fpnz9R6OsOo47*%8qZ-+>&EylNKX;FII zxU?rD*c|lC8KZc_5ig;~iyAKEo<+XnL2_2QeCfu;xg^FAR$9(Q2^ltFP7vv0Rxob4 Vm0<`pO2Q-xqsDY|`~!!O04cx6#ufko delta 403 zcmV;E0c`%B1cn5VeSghvgD?!f?_>qsOpHM3KZFu-N@vpFY2=afTb&HGk0-P9j?s9JA6x%X*0o z3s9LvVi7o~ijWqtw}$u*6)cYVZaQq!VUuoYiM{#sI}%y}Qv9O5(Fiv>mN{y7(mq87 z<(5sh)#<8FYNhYHLbt=5)zmkS za1TudlvI<@ZGX7uVk*^GJLlk8gtP1%-}S9KGf_n@miuFI3iP3`H-uc*=k<+Skf1q! z3UcM4UX>gJGNZ!`tP`cGzdJ-C(HQ;5OOMjx-lP*5LFXWsMk(QDZ1EC$zNy=d+_TAd x+(_<(tZuq8Q7+M!Rgs}8#{I(22_jj}3WtU3Dck}LV+=ou{HRgm9Dj1Kpz5lv!}0(C diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 35369c947aa4106bd8c48c98d7fc1c6073ee9eb3..38c7fb36172cad9a59dfe24ced01b0aeff8d5537 100644 GIT binary patch delta 13 Ucmb=gXP58h;5fIqZ6bRG03W6V#{d8T delta 13 Ucmb=gXP58h;COD^I+48s03JF7c>n+a diff --git a/utils/index.html b/utils/index.html index 4d3fbbe7..b8d1b285 100644 --- a/utils/index.html +++ b/utils/index.html @@ -651,8 +651,7 @@

    Source code in kstreams/utils.py -
    54
    -55
    +            
    55
     56
     57
     58
    @@ -689,7 +688,8 @@ 

    89 90 91 -92

    def create_ssl_context(
    +92
    +93
    def create_ssl_context(
         *,
         cafile: Optional[str] = None,
         capath: Optional[str] = None,
    @@ -828,8 +828,7 @@ 

    Source code in kstreams/utils.py -
    15
    -16
    +            
    16
     17
     18
     19
    @@ -864,7 +863,8 @@ 

    48 49 50 -51

    def create_ssl_context_from_mem(
    +51
    +52
    def create_ssl_context_from_mem(
         *,
         certdata: str,
         keydata: str,