Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
d102032c
Commit
d102032c
authored
4 years ago
by
Daniel Lyons
Browse files
Options
Downloads
Patches
Plain Diff
Second try at typing this module
parent
d2297066
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shared/channels/src/channels/amqp_helpers.py
+11
-8
11 additions, 8 deletions
shared/channels/src/channels/amqp_helpers.py
with
11 additions
and
8 deletions
shared/channels/src/channels/amqp_helpers.py
+
11
−
8
View file @
d102032c
from
abc
import
ABC
,
abstractmethod
from
typing
import
Callable
,
Any
,
Optional
,
Union
,
TypeVar
,
Protocol
from
typing
import
Callable
,
Any
,
Optional
,
Union
,
TypeVar
,
Protocol
,
Generic
import
pika
from
marshmallow
import
Schema
...
...
@@ -8,10 +8,10 @@ from pycapo import CapoConfig
from
workspaces.json
import
WorkflowEventSchema
from
workspaces.schema
import
WorkflowEvent
T
=
TypeVar
(
'
T
'
)
T
=
TypeVar
(
'
T
'
,
contravariant
=
True
)
class
ChannelDefinition
(
ABC
,
Protocol
[
T
]):
class
ChannelDefinition
(
Protocol
[
T
]):
@abstractmethod
def
routing_key_for
(
self
,
message
:
T
)
->
str
:
pass
...
...
@@ -49,10 +49,13 @@ class WorkflowEventChannel(ChannelDefinition[WorkflowEvent]):
return
self
.
EXCHANGE
class
Channel
(
Protocol
[
T
]):
CONNECTION
=
None
CHANNEL
=
None
CONFIG
=
None
ChannelDef
=
TypeVar
(
'
ChannelDef
'
,
bound
=
ChannelDefinition
,
covariant
=
True
)
class
Channel
(
Generic
[
ChannelDef
]):
CONNECTION
:
pika
.
BlockingConnection
=
None
CHANNEL
:
BlockingChannel
=
None
CONFIG
:
CapoConfig
=
None
def
__init__
(
self
,
definition
:
ChannelDefinition
[
T
]):
self
.
definition
=
definition
...
...
@@ -137,4 +140,4 @@ class Channel(Protocol[T]):
# Predefined event channels for ease of use
workflow_events
=
Channel
(
WorkflowEventChannel
())
workflow_events
:
Channel
[
WorkflowEvent
]
=
Channel
(
WorkflowEventChannel
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment