DalgoT4D / prefect-proxy

GNU Affero General Public License v3.0
0 stars 7 forks source link

Cancel_flow_run #105

Closed huzaifmalik786 closed 4 months ago

huzaifmalik786 commented 4 months ago

Description

This PR closes #104 . A new function has been added which accepts the flow_run_id as a parameter and cancels it.

Implementation Details

  1. Inside proxy/service.py, a new function cancel_flow_run has been added which takes flow_run_id as a parameter and change it's state to Cancelled.
  2. Inside tests/test_service.py:
    • function test_cancel_flow_run_type_error has been added to check for any flow_run_id type error.
    • function test_cancel_flow_run_failure had been added to handle any case of failure.
    • function test_cancel_flow_run_success checks for successful execution of the function.

Tasks Completed

Ishankoradia commented 4 months ago

@huzaifmalik786 this doesn't work as expected since get_client is an async context manager.

Please take a look here https://docs.prefect.io/latest/guides/using-the-client/ for examples. Then you can update your PR. Thanks.

huzaifmalik786 commented 4 months ago

@Ishankoradia working on it,

huzaifmalik786 commented 4 months ago

@Ishankoradia Please check it now.

huzaifmalik786 commented 4 months ago

@Ishankoradia @fatchat Please let me know if anything seems wrong with the PR.

fatchat commented 4 months ago

good morning @huzaifmalik786

the function works as expected. but the tests are failing

  1. please write your three test functions using async def instead of def
  2. call your function using await cancel_flow_run in each of them
  3. You can't mock the function you're testing, you will instead mock the functions which it calls. So you will mock proxy.service.get_client

You will have to google AsyncMock to set this up correctly

To run the test suite you will need a GCP service account JSON. It doesn't need to have any permissions, so just create a service account in your GCP console and download the JSON.

If the file is saved locally on your laptop as service.json then run the test suite with

GOOGLE_APPLICATION_CREDENTIALS="service.json" pytest --asyncio-mode=auto

huzaifmalik786 commented 4 months ago

Good morning @fatchat . I'll make the required changes. Thank You!