Skip to content

Add empty param name support#10

Merged
s3rius merged 4 commits intotaskiq-python:developfrom
cofob:feature-empty-param
Aug 23, 2023
Merged

Add empty param name support#10
s3rius merged 4 commits intotaskiq-python:developfrom
cofob:feature-empty-param

Conversation

@cofob
Copy link
Contributor

@cofob cofob commented Aug 19, 2023

Test code:

import asyncio

from taskiq import InMemoryBroker

from taskiq_pipelines import EMPTY_PARAM_NAME, Pipeline, PipelineMiddleware

broker = InMemoryBroker()
broker.add_middlewares(PipelineMiddleware())


@broker.task
async def add_one(value: int) -> int:
    return value + 1


@broker.task
async def do_nothing() -> None:
    print("I'm doing nothing.")


async def main() -> None:
    # Never forget to call startup in the beginning.
    await broker.startup()

    pipe = (
        Pipeline(broker, add_one).call_next(do_nothing, param_name=EMPTY_PARAM_NAME)
    )
    task = await pipe.kiq(2)

    await asyncio.sleep(2)


if __name__ == "__main__":
    asyncio.run(main())

@s3rius
Copy link
Member

s3rius commented Aug 20, 2023

@cofob, thanks you very much for contribution.

I have an Idea. I guess, it would be really nice to create a separate function that sets this parameter to EMPTY_PARAM_NAME and do not expose the constant to users. You may call it call_after and just remove param_name argument.

As I see it, it would be easier since you would not need to import anything and it would be easier to maintain backward compatibility.

async def main() -> None:
    # Never forget to call startup in the beginning.
    await broker.startup()

    pipe = Pipeline(broker, add_one).call_after(do_nothing)
    task = await pipe.kiq(2)

    await asyncio.sleep(2)

What do you think?

@cofob
Copy link
Contributor Author

cofob commented Aug 21, 2023

@s3rius added call_after. Please review.

@cofob cofob force-pushed the feature-empty-param branch from 6605d63 to ad62ed3 Compare August 23, 2023 11:59
@s3rius s3rius merged commit 367efa4 into taskiq-python:develop Aug 23, 2023
@cofob cofob deleted the feature-empty-param branch August 23, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants