Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1129 - Create a publish command for the CLI #1151

Merged
merged 22 commits into from
Mar 11, 2024

Conversation

MRLab12
Copy link
Contributor

@MRLab12 MRLab12 commented Jan 17, 2024

Description

Users should be able to publish a test message right from the command line. To do this, a publish command has been added to the CLI main.py file.

Close #1129

How to Test

To test the new publish functionality introduced in this Pull Request, follow these steps:

  1. Start Your FastStream Application: First, you need to have a running FastStream application. You can start your application with the following command, assuming your FastStream application is defined in a file named testfaststreamapp.py:

    python testfaststreamapp.py

    Make sure your FastStream application is set up to subscribe to a channel named input_channel and publishes processed messages to another channel (e.g., output_channel). Here's a simple example of what your testfaststreamapp.py might contain:

    from faststream import FastStream
    from faststream.redis import RedisBroker
    
    broker = RedisBroker("redis://localhost:6379")
    app = FastStream(broker=broker)
    
    @broker.subscriber(channel="input_channel")
    @broker.publisher(channel="output_channel")
    async def process_message(message: str) -> str:
        print(f"Received message: {message}")
        return f"Processed: {message}"
    
    if __name__ == "__main__":
        app.run()
  2. Send a Test Message: With your FastStream application running, you can send a test message using the faststream publish command. Use the following command to publish a message to the input_channel:

    faststream publish testfaststreamapp:app "Hello World" --channel "input_channel" --rpc

Type of change

  • New feature (a non-breaking change that adds functionality)
  • This change requires a documentation update

Checklist

  • My code adheres to the style guidelines of this project (scripts/lint.sh shows no errors)
  • I have conducted a self-review of my own code
  • I have made the necessary changes to the documentation
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • Both new and existing unit tests pass successfully on my local environment by running scripts/test-cov.sh
  • I have ensured that static analysis tests are passing by running scripts/static-anaylysis.sh
  • I have included code examples to illustrate the modifications

@MRLab12
Copy link
Contributor Author

MRLab12 commented Jan 17, 2024

Having issues running tests locally. They seem to get stuck and the test run never finishes.

Opened this draft PR to get eyes on the work and get feedback on whether the changes here fulfill the requirements of adding this feature.

@Lancetnik Lancetnik added the enhancement New feature or request label Jan 17, 2024
@davorrunje davorrunje requested a review from kumaranvpl January 22, 2024 19:00
@davorrunje
Copy link
Collaborator

@MRLab12 do you need help with this?

@MRLab12
Copy link
Contributor Author

MRLab12 commented Jan 22, 2024

Hey @davorrunje , this PR is in Draft because I wanted to check I had the correct logic and if the code changes are doing the intended changes. I haven't looked into the tests yet, will check.

If it looks good to be reviewed, I can mark it ready. Would also be helpful if you can recommend next steps for documenting and other checks before having this PR ready to be deployed.

@davorrunje davorrunje marked this pull request as ready for review February 2, 2024 20:25
@davorrunje
Copy link
Collaborator

davorrunje commented Feb 2, 2024

@MRLab12 can you please give me write access to your repo, I would like to push some changes to your branch

@MRLab12
Copy link
Contributor Author

MRLab12 commented Feb 2, 2024

@davorrunje Sent you invite for access.

@davorrunje
Copy link
Collaborator

@MRLab12 The tests are failing for Python versions 3.8 and 3.9. Can you please check locally with the following command:

bash scripts/test.sh -m "(slow and (not nats and not kafka and not confluent and not rabbit and not redis)) or (not nats and not kafka and not confluent and not rabbit and not redis)"

I think your tests are interfering with the rest. Can you please check the way you handle async code and compare it with the run function and its tests?

@davorrunje davorrunje requested review from davorrunje and removed request for kumaranvpl February 5, 2024 07:01
@davorrunje davorrunje removed their assignment Feb 5, 2024
@MRLab12
Copy link
Contributor Author

MRLab12 commented Feb 6, 2024

@davorrunje Thanks for the help with this. It is in fact the tests that I added that are not properly handling the async event loop. Looking into and should have a fix coming up.

@MRLab12
Copy link
Contributor Author

MRLab12 commented Mar 7, 2024

@davorrunje Hey I was really busy with interviews and did not have a chance to take a look a this. I was able to find that adding @pytest.mark.asyncio to the tests seems to properly end the event loop. It is a weird to use it this way since the test are not using async, but the publish command is. Let me know if this works or we should handle tests some other way.

@davorrunje davorrunje added this pull request to the merge queue Mar 11, 2024
@davorrunje
Copy link
Collaborator

@MRLab12 Thanx for the PR, I am merging it now :)

Merged via the queue into airtai:main with commit d7fef0c Mar 11, 2024
31 checks passed
@davorrunje davorrunje deleted the 1129-CLI-publish-command branch March 11, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Feature: CLI publish command
3 participants