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

Multi-capability and svc2svc support for services #9

Merged
merged 10 commits into from
Aug 21, 2024
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pdm-project/pdm
rev: 2.11.2
rev: 2.17.2
hooks:
- id: pdm-export
args: ['--without-hashes']
Expand Down
27 changes: 27 additions & 0 deletions docs/api/callback_definitions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
====================
Callback Definitions
====================

Shared
======

.. automodule:: intersect_sdk.shared_callback_definitions
:members:
:undoc-members:
:exclude-members: model_computed_fields, model_config, model_fields

Client
======

.. automodule:: intersect_sdk.client_callback_definitions
:members:
:undoc-members:
:exclude-members: model_computed_fields, model_config, model_fields

Service
=======

.. automodule:: intersect_sdk.service_callback_definitions
:members:
:undoc-members:
:exclude-members: model_computed_fields, model_config, model_fields
7 changes: 0 additions & 7 deletions docs/api/client_callback_definitions.rst

This file was deleted.

27 changes: 27 additions & 0 deletions docs/api/config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
======
Config
======

Config - Shared
===============

.. automodule:: intersect_sdk.config.shared
:members:
:undoc-members:
:exclude-members: model_computed_fields, model_config, model_fields

Config - Service
================

.. automodule:: intersect_sdk.config.service
:members:
:undoc-members:
:exclude-members: model_computed_fields, model_config, model_fields

Config - Client
===============

.. automodule:: intersect_sdk.config.client
:members:
:undoc-members:
:exclude-members: model_computed_fields, model_config, model_fields
7 changes: 0 additions & 7 deletions docs/api/config_client.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/config_service.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/config_shared.rst

This file was deleted.

8 changes: 3 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ This site provides documentation for INTERSECT's Python SDK. See the getting sta
:maxdepth: 2
:caption: API documentation

api/config_service
api/config_client
api/config_shared
api/config
api/core_definitions
api/schema
api/capability
api/service_definitions
api/service
api/client_callback_definitions
api/service_definitions
api/client
api/callback_definitions
api/app_lifecycle
api/constants
api/version
Expand Down
6 changes: 3 additions & 3 deletions examples/1_hello_world/hello_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
IntersectClient,
IntersectClientCallback,
IntersectClientConfig,
IntersectClientMessageParams,
IntersectDirectMessageParams,
default_intersect_lifecycle_loop,
)

Expand Down Expand Up @@ -74,9 +74,9 @@ def simple_client_callback(
you'll get a message back.
"""
initial_messages = [
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='hello-organization.hello-facility.hello-system.hello-subsystem.hello-service',
operation='say_hello_to_name',
operation='HelloExample.say_hello_to_name',
payload='hello_client',
)
]
Expand Down
3 changes: 2 additions & 1 deletion examples/1_hello_world/hello_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ def say_hello_to_name(self, name: str) -> str:
@intersect_message and @intersect_status, and that these functions are appropriately type-annotated.
"""
capability = HelloServiceCapabilityImplementation()
capability.capability_name = 'HelloExample'

"""
step three - create service from both the configuration and your own capability
"""
service = IntersectService(capability, config)
service = IntersectService([capability], config)

"""
step four - start lifecycle loop. The only necessary parameter is your service.
Expand Down
6 changes: 3 additions & 3 deletions examples/1_hello_world_amqp/hello_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
IntersectClient,
IntersectClientCallback,
IntersectClientConfig,
IntersectClientMessageParams,
IntersectDirectMessageParams,
default_intersect_lifecycle_loop,
)

Expand Down Expand Up @@ -76,9 +76,9 @@ def simple_client_callback(
you'll get a message back.
"""
initial_messages = [
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='hello-organization.hello-facility.hello-system.hello-subsystem.hello-service',
operation='say_hello_to_name',
operation='HelloExample.say_hello_to_name',
payload='hello_client',
)
]
Expand Down
3 changes: 2 additions & 1 deletion examples/1_hello_world_amqp/hello_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ def say_hello_to_name(self, name: str) -> str:
@intersect_message and @intersect_status, and that these functions are appropriately type-annotated.
"""
capability = HelloServiceCapabilityImplementation()
capability.capability_name = 'HelloExample'

"""
step three - create service from both the configuration and your own capability
"""
service = IntersectService(capability, config)
service = IntersectService([capability], config)

"""
step four - start lifecycle loop. The only necessary parameter is your service.
Expand Down
6 changes: 3 additions & 3 deletions examples/1_hello_world_events/hello_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
IntersectClient,
IntersectClientCallback,
IntersectClientConfig,
IntersectClientMessageParams,
IntersectDirectMessageParams,
default_intersect_lifecycle_loop,
)

Expand Down Expand Up @@ -95,9 +95,9 @@ def simple_event_callback(
you'll get a message back.
"""
initial_messages = [
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='hello-organization.hello-facility.hello-system.hello-subsystem.hello-service',
operation='say_hello_to_name',
operation='HelloExample.say_hello_to_name',
payload='hello_client',
)
]
Expand Down
3 changes: 2 additions & 1 deletion examples/1_hello_world_events/hello_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ def say_hello_to_name(self, name: str) -> str:
@intersect_message and @intersect_status, and that these functions are appropriately type-annotated.
"""
capability = HelloServiceCapabilityImplementation()
capability.capability_name = 'HelloExample'

"""
step three - create service from both the configuration and your own capability
"""
service = IntersectService(capability, config)
service = IntersectService([capability], config)

"""
step four - start lifecycle loop. The only necessary parameter is your service.
Expand Down
30 changes: 15 additions & 15 deletions examples/2_counting/counting_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
IntersectClient,
IntersectClientCallback,
IntersectClientConfig,
IntersectClientMessageParams,
IntersectDirectMessageParams,
default_intersect_lifecycle_loop,
)

Expand Down Expand Up @@ -38,54 +38,54 @@ def __init__(self) -> None:
self.message_stack = [
# wait 5 seconds before stopping the counter. "Count" in response will be approx. 6
(
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='counting-organization.counting-facility.counting-system.counting-subsystem.counting-service',
operation='stop_count',
operation='CountingExample.stop_count',
payload=None,
),
5.0,
),
# start the counter up again - it will not be 0 at this point! "Count" in response will be approx. 7
(
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='counting-organization.counting-facility.counting-system.counting-subsystem.counting-service',
operation='start_count',
operation='CountingExample.start_count',
payload=None,
),
1.0,
),
# reset the counter, but have it immediately start running again. "Count" in response will be approx. 10
(
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='counting-organization.counting-facility.counting-system.counting-subsystem.counting-service',
operation='reset_count',
operation='CountingExample.reset_count',
payload=True,
),
3.0,
),
# reset the counter, but don't have it run again. "Count" in response will be approx. 6
(
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='counting-organization.counting-facility.counting-system.counting-subsystem.counting-service',
operation='reset_count',
operation='CountingExample.reset_count',
payload=False,
),
5.0,
),
# start the counter back up. "Count" in response will be approx. 1
(
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='counting-organization.counting-facility.counting-system.counting-subsystem.counting-service',
operation='start_count',
operation='CountingExample.start_count',
payload=None,
),
3.0,
),
# finally, stop the counter one last time. "Count" in response will be approx. 4
(
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='counting-organization.counting-facility.counting-system.counting-subsystem.counting-service',
operation='stop_count',
operation='CountingExample.stop_count',
payload=None,
),
3.0,
Expand Down Expand Up @@ -158,9 +158,9 @@ def client_callback(
# The counter will start after the initial message.
# If the service is already active and counting, this may do nothing.
initial_messages = [
IntersectClientMessageParams(
IntersectDirectMessageParams(
destination='counting-organization.counting-facility.counting-system.counting-subsystem.counting-service',
operation='start_count',
operation='CountingExample.start_count',
payload=None,
)
]
Expand Down
3 changes: 2 additions & 1 deletion examples/2_counting/counting_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def _run_count(self) -> None:
**from_config_file,
)
capability = CountingServiceCapabilityImplementation()
service = IntersectService(capability, config)
capability.capability_name = 'CountingExample'
service = IntersectService([capability], config)
logger.info('Starting counting_service, use Ctrl+C to exit.')
default_intersect_lifecycle_loop(
service,
Expand Down
3 changes: 2 additions & 1 deletion examples/2_counting_events/counting_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def increment_counter_function(self) -> None:
**from_config_file,
)
capability = CountingServiceCapabilityImplementation()
service = IntersectService(capability, config)
capability.capability_name = 'CountingExample'
service = IntersectService([capability], config)
logger.info('Starting counting_service, use Ctrl+C to exit.')

"""
Expand Down
4 changes: 2 additions & 2 deletions examples/3_ping_pong_events/ping_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logging.basicConfig(level=logging.INFO)


class PingCapabiilityImplementation(P_ngBaseCapabilityImplementation):
class PingCapabilityImplementation(P_ngBaseCapabilityImplementation):
"""Basic capability definition, very similar to the other capability except for the type of event it emits."""

def after_service_startup(self) -> None:
Expand All @@ -32,4 +32,4 @@ def ping_event(self) -> None:


if __name__ == '__main__':
run_service(PingCapabiilityImplementation())
run_service(PingCapabilityImplementation())
4 changes: 2 additions & 2 deletions examples/3_ping_pong_events/pong_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logging.basicConfig(level=logging.INFO)


class PongCapabiilityImplementation(P_ngBaseCapabilityImplementation):
class PongCapabilityImplementation(P_ngBaseCapabilityImplementation):
"""Basic capability definition, very similar to the other capability except for the type of event it emits."""

def after_service_startup(self) -> None:
Expand All @@ -32,4 +32,4 @@ def pong_event(self) -> None:


if __name__ == '__main__':
run_service(PongCapabiilityImplementation())
run_service(PongCapabilityImplementation())
3 changes: 2 additions & 1 deletion examples/3_ping_pong_events/service_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def run_service(capability: P_ngBaseCapabilityImplementation) -> None:
status_interval=30.0,
**from_config_file,
)
service = IntersectService(capability, config)
capability.capability_name = service_name
service = IntersectService([capability], config)
logger.info('Starting %s_service, use Ctrl+C to exit.', service_name)

"""
Expand Down
4 changes: 2 additions & 2 deletions examples/3_ping_pong_events_amqp/ping_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logging.getLogger('pika').setLevel(logging.WARNING)


class PingCapabiilityImplementation(P_ngBaseCapabilityImplementation):
class PingCapabilityImplementation(P_ngBaseCapabilityImplementation):
"""Basic capability definition, very similar to the other capability except for the type of event it emits."""

def after_service_startup(self) -> None:
Expand All @@ -33,4 +33,4 @@ def ping_event(self) -> None:


if __name__ == '__main__':
run_service(PingCapabiilityImplementation())
run_service(PingCapabilityImplementation())
4 changes: 2 additions & 2 deletions examples/3_ping_pong_events_amqp/pong_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logging.getLogger('pika').setLevel(logging.WARNING)


class PongCapabiilityImplementation(P_ngBaseCapabilityImplementation):
class PongCapabilityImplementation(P_ngBaseCapabilityImplementation):
"""Basic capability definition, very similar to the other capability except for the type of event it emits."""

def after_service_startup(self) -> None:
Expand All @@ -33,4 +33,4 @@ def pong_event(self) -> None:


if __name__ == '__main__':
run_service(PongCapabiilityImplementation())
run_service(PongCapabilityImplementation())
Loading
Loading