- 
                Notifications
    
You must be signed in to change notification settings  - Fork 32
 
          ⚠️🎨✨ Execute the api-server's run and map function api endpoints in celery worker
          #8233
        
          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
          
     Merged
      
      
            mrnicegyu11
  merged 126 commits into
  ITISFoundation:master
from
bisgaard-itis:1973-add-celery-worker-to-api-server
  
      
      
   
  Sep 3, 2025 
      
    
  
     Merged
                    Changes from 124 commits
      Commits
    
    
            Show all changes
          
          
            126 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      ada3cc1
              
                add celery-library as api-server dependency
              
              
                bisgaard-itis 1350f84
              
                initial setup of celery worker
              
              
                bisgaard-itis b8c494e
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 8813fa5
              
                fix openapi-specs make target in api-server
              
              
                bisgaard-itis 4a822e5
              
                fix openapi specs generation in api-server
              
              
                bisgaard-itis 22c6c2e
              
                name fix
              
              
                bisgaard-itis b8325d8
              
                first attempt at definining run function task
              
              
                bisgaard-itis 1b43976
              
                minor adjustments
              
              
                bisgaard-itis 7e57cd9
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 25eaaaa
              
                improve docs and minor changes
              
              
                bisgaard-itis ed6ed1e
              
                cleanup and reset docs
              
              
                bisgaard-itis 2f57d5e
              
                register task
              
              
                bisgaard-itis f4b4af8
              
                add celery client inside api-server
              
              
                bisgaard-itis 8b3ed88
              
                ensure requirements are set
              
              
                bisgaard-itis 94324cf
              
                cleanup fixtures
              
              
                bisgaard-itis e279206
              
                insert fake run_function
              
              
                bisgaard-itis 8e49543
              
                check mock
              
              
                bisgaard-itis 80a7cca
              
                transform run function endpoint
              
              
                bisgaard-itis a06118f
              
                add pytest-celery plugin
              
              
                bisgaard-itis f55363c
              
                can run empty test
              
              
                bisgaard-itis 8f847f6
              
                minor changes
              
              
                bisgaard-itis 5a6d47e
              
                test fix
              
              
                bisgaard-itis 1d4df87
              
                further improvements to test
              
              
                bisgaard-itis 33653cd
              
                add fakeredis dependency
              
              
                bisgaard-itis c91abad
              
                further additions to tests
              
              
                bisgaard-itis 653dbbc
              
                fix for logstreamer
              
              
                bisgaard-itis 676aa32
              
                do full round trip in test
              
              
                bisgaard-itis 162c8ee
              
                test passing
              
              
                bisgaard-itis 18effae
              
                start converting task tests
              
              
                bisgaard-itis c297397
              
                minor change
              
              
                bisgaard-itis 0683715
              
                minor changes
              
              
                bisgaard-itis 2021ac0
              
                add examples to celery-library models and use them in mocks
              
              
                bisgaard-itis 51e0b95
              
                first test passing
              
              
                bisgaard-itis b471434
              
                further corrections to tests
              
              
                bisgaard-itis 47e9fd1
              
                add fixture
              
              
                bisgaard-itis 7d329f6
              
                further additions
              
              
                bisgaard-itis ca2c013
              
                ensure all task tests pass
              
              
                bisgaard-itis 5824f2b
              
                finish task tests
              
              
                bisgaard-itis 77ac520
              
                add test for exception propagation from celery
              
              
                bisgaard-itis 91ed6f1
              
                add inputs in run function test
              
              
                bisgaard-itis 95de5a5
              
                add api-worker to docker compose
              
              
                bisgaard-itis e6eb80c
              
                add new fixtures and model examples
              
              
                bisgaard-itis bc263b0
              
                first attempt to add boot script for api-server worker
              
              
                bisgaard-itis 6b73791
              
                add health check to api-server celery worker
              
              
                bisgaard-itis 6c10aed
              
                add asgi_lifespan to servicelib.fastapi reqs as it was missing
              
              
                bisgaard-itis 157bbac
              
                fixes to make services functional again
              
              
                bisgaard-itis 568817b
              
                add redis env vars to api-server
              
              
                bisgaard-itis 329354f
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis e8683a9
              
                add separate rabbitmq queue for api-worker
              
              
                bisgaard-itis 1400a42
              
                add test of task function itself
              
              
                bisgaard-itis 7d6d4c9
              
                register job pydantic types for serialization - can run function via …
              
              
                bisgaard-itis 4a327f8
              
                cosmetic fix
              
              
                bisgaard-itis 4dcf9bd
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 3efc130
              
                change boot process for celery worker
              
              
                bisgaard-itis 75a06d5
              
                fix test_tasks.py
              
              
                bisgaard-itis c1a67d5
              
                add test for full round trip of running function
              
              
                bisgaard-itis 4acf14a
              
                fix typecheck
              
              
                bisgaard-itis bec7cf2
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis f49f9ef
              
                update openapi specs
              
              
                bisgaard-itis 42a6133
              
                add example in RegisteredProjectFunctionGet
              
              
                bisgaard-itis 60a0b8b
              
                fix example of TaskStatus
              
              
                bisgaard-itis 7fbaab6
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis ab428ac
              
                upgrade fakeredis dependency in api-server
              
              
                bisgaard-itis 9709eec
              
                fix pylinting
              
              
                bisgaard-itis 53645b6
              
                make pylint happy
              
              
                bisgaard-itis b1d306e
              
                fix pylint after formatting
              
              
                bisgaard-itis 5a2b652
              
                pylint fix
              
              
                bisgaard-itis ff376a7
              
                remove worker services from public api integration tests
              
              
                bisgaard-itis 8391dfd
              
                add api-worker in docker-compose.local.yml
              
              
                bisgaard-itis 7ece751
              
                add api-worker in docker-compose.devel.yml
              
              
                bisgaard-itis cf57e04
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 4eb2262
              
                factor out function run pre check
              
              
                bisgaard-itis b306b19
              
                add test for checking function job patch method
              
              
                bisgaard-itis 0a94743
              
                start creating patch endpoint for function jobs
              
              
                bisgaard-itis 8c3b881
              
                missing files
              
              
                bisgaard-itis d829b01
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 10df578
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 981736f
              
                add mehod for patching a registered function job to function job service
              
              
                bisgaard-itis 4f989b6
              
                implement run function workflow
              
              
                bisgaard-itis 0a75a8d
              
                minor fix
              
              
                bisgaard-itis 1230692
              
                typecheck fix
              
              
                bisgaard-itis e18088a
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 52288be
              
                propagate pre_registered_function_job_id properly
              
              
                bisgaard-itis 07f7ec8
              
                cleanup
              
              
                bisgaard-itis bf6bb7e
              
                fix fake run fcn test
              
              
                bisgaard-itis ff8b50a
              
                fix tests
              
              
                bisgaard-itis 34ee07f
              
                test fix
              
              
                bisgaard-itis eebdf2f
              
                pylint fix
              
              
                bisgaard-itis 50695b3
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis fc7b39e
              
                implement function job status endpoint
              
              
                bisgaard-itis 8ed5bbd
              
                start implementing test for getting function job status
              
              
                bisgaard-itis eab5e08
              
                finish test for getting function job status
              
              
                bisgaard-itis 9401f48
              
                fix get function job outputs and test
              
              
                bisgaard-itis 55df241
              
                add implementation for map endpoint
              
              
                bisgaard-itis 95ae30d
              
                move test so that it uses celery worker
              
              
                bisgaard-itis 21cd8ae
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 2ce52b6
              
                update openapi-specs
              
              
                bisgaard-itis 979cc2c
              
                make pylint happy
              
              
                bisgaard-itis bd64fea
              
                typecheck
              
              
                bisgaard-itis 3774f00
              
                celery -> celery_worker
              
              
                bisgaard-itis b8b69fe
              
                correct examples added to pydantic models @sanderegg
              
              
                bisgaard-itis b41eb5a
              
                improve dependency-injection system comment @sanderegg
              
              
                bisgaard-itis b36d5ff
              
                massage -> preprocess
              
              
                bisgaard-itis 9c154e4
              
                @pcrespov use contextlib.suppress
              
              
                bisgaard-itis 313cc1d
              
                avoid converting CeleryError to HTTPException directly in endpoint ha…
              
              
                bisgaard-itis fb2e994
              
                return 503 instead of 500 when celery task fails @sanderegg
              
              
                bisgaard-itis f272e6f
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis a640f4c
              
                test fixes
              
              
                bisgaard-itis 7b5cda8
              
                return 503 in case of CeleryError @sanderegg
              
              
                bisgaard-itis 4e09ac3
              
                use pytest-simcore fixture
              
              
                bisgaard-itis 46f1bd4
              
                typecheck issue fix
              
              
                bisgaard-itis 02a9860
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis 098018a
              
                fix the typecheck fix
              
              
                bisgaard-itis 228fae9
              
                move pytest_plugins to toplevel conftest
              
              
                bisgaard-itis e057a26
              
                fix tests
              
              
                bisgaard-itis eb6de3b
              
                fix mock
              
              
                bisgaard-itis 22a2226
              
                Merge branch 'master' into 1973-add-celery-worker-to-api-server
              
              
                bisgaard-itis b356c2b
              
                @pcrespov simply reraise exception to return 500 status cod
              
              
                bisgaard-itis 4eaea73
              
                @pcrespov decouple setup of celery task manager from dependencies sub…
              
              
                bisgaard-itis faeac06
              
                @GitHK poll_task_until_done -> wait_for_task_result
              
              
                bisgaard-itis a51a42c
              
                @GitHK wait fixed 1 sec
              
              
                bisgaard-itis 7f20a84
              
                pylint fix
              
              
                bisgaard-itis 76aecfe
              
                ensure ordering of jobs is preserved
              
              
                bisgaard-itis 312e853
              
                first attempt to test job_id order
              
              
                bisgaard-itis fa4f7ad
              
                Revert "first attempt to test job_id order"
              
              
                bisgaard-itis 9172a39
              
                fix fixture for creating celery app
              
              
                bisgaard-itis File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            96 changes: 96 additions & 0 deletions
          
          96 
        
  packages/pytest-simcore/src/pytest_simcore/celery_library_mocks.py
  
  
      
      
   
        
      
      
    
                              
      
                  bisgaard-itis marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
            
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # pylint: disable=redefined-outer-name | ||
| 
     | 
||
| from collections.abc import Callable | ||
| 
     | 
||
| import pytest | ||
| from faker import Faker | ||
| from pytest_mock import MockerFixture, MockType | ||
| from servicelib.celery.models import TaskStatus, TaskUUID | ||
| from servicelib.celery.task_manager import Task, TaskManager | ||
| 
     | 
||
| _faker = Faker() | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def submit_task_return_value() -> TaskUUID: | ||
| return TaskUUID(_faker.uuid4()) | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def cancel_task_return_value() -> None: | ||
| return None | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def get_task_result_return_value() -> dict: | ||
| return {"result": "example"} | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def get_task_status_return_value() -> TaskStatus: | ||
| example = TaskStatus.model_json_schema()["examples"][0] | ||
| return TaskStatus.model_validate(example) | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def list_tasks_return_value() -> list[Task]: | ||
| examples = Task.model_json_schema()["examples"] | ||
| assert len(examples) > 0 | ||
| return [Task.model_validate(example) for example in examples] | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def set_task_progress_return_value() -> None: | ||
| return None | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def mock_task_manager_object( | ||
| mocker: MockerFixture, | ||
| submit_task_return_value: TaskUUID, | ||
| cancel_task_return_value: None, | ||
| get_task_result_return_value: dict, | ||
| get_task_status_return_value: TaskStatus, | ||
| list_tasks_return_value: list[Task], | ||
| set_task_progress_return_value: None, | ||
| ) -> MockType: | ||
| """ | ||
| Returns a TaskManager mock with overridable return values for each method. | ||
| If a return value is an Exception, the method will raise it. | ||
| """ | ||
| mock = mocker.Mock(spec=TaskManager) | ||
| 
     | 
||
| def _set_return_or_raise(method, value): | ||
| if isinstance(value, Exception): | ||
| method.side_effect = lambda *a, **kw: (_ for _ in ()).throw(value) | ||
| else: | ||
| method.return_value = value | ||
| 
     | 
||
| _set_return_or_raise(mock.submit_task, submit_task_return_value) | ||
| _set_return_or_raise(mock.cancel_task, cancel_task_return_value) | ||
| _set_return_or_raise(mock.get_task_result, get_task_result_return_value) | ||
| _set_return_or_raise(mock.get_task_status, get_task_status_return_value) | ||
| _set_return_or_raise(mock.list_tasks, list_tasks_return_value) | ||
| _set_return_or_raise(mock.set_task_progress, set_task_progress_return_value) | ||
| return mock | ||
| 
     | 
||
| 
     | 
||
| @pytest.fixture | ||
| def mock_task_manager_object_raising_factory( | ||
| mocker: MockerFixture, | ||
| ) -> Callable[[Exception], MockType]: | ||
| def _factory(task_manager_exception: Exception) -> MockType: | ||
| mock = mocker.Mock(spec=TaskManager) | ||
| 
     | 
||
| def _raise_exc(*args, **kwargs): | ||
| raise task_manager_exception | ||
| 
     | 
||
| mock.submit_task.side_effect = _raise_exc | ||
| mock.cancel_task.side_effect = _raise_exc | ||
| mock.get_task_result.side_effect = _raise_exc | ||
| mock.get_task_status.side_effect = _raise_exc | ||
| mock.list_tasks.side_effect = _raise_exc | ||
| mock.set_task_progress.side_effect = _raise_exc | ||
| return mock | ||
| 
     | 
||
| return _factory | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.