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
0d2ed104
Commit
0d2ed104
authored
4 years ago
by
Daniel Lyons
Browse files
Options
Downloads
Patches
Plain Diff
Add a sketch of a channel API for simple use cases in other projects
parent
344025e4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shared/channels/amqp_helpers.py
+41
-1
41 additions, 1 deletion
shared/channels/amqp_helpers.py
with
41 additions
and
1 deletion
shared/channels/amqp_helpers.py
+
41
−
1
View file @
0d2ed104
from
typing
import
Callable
from
typing
import
Callable
,
Any
import
pika
from
marshmallow
import
Schema
from
pycapo
import
CapoConfig
from
workspaces.json
import
WorkflowEventSchema
def
make_amqp_connection
(
profile
:
str
)
->
pika
.
BlockingConnection
:
...
...
@@ -82,3 +84,41 @@ def receive_amqp_message(
channel
.
queue_bind
(
queue
=
queue_name
,
exchange
=
exchange
,
routing_key
=
routing_key
)
channel
.
basic_consume
(
queue
=
queue_name
,
on_message_callback
=
callback
,
auto_ack
=
auto_ack
)
channel
.
start_consuming
()
class
Channel
:
def
__init__
(
self
,
schema
:
Schema
):
self
.
schema
=
schema
def
connect
(
self
):
# FIXME implement this
pass
def
close
(
self
):
# FIXME implement this
pass
def
send
(
self
,
event
):
# I don't know how to type Event there for Python but it would be
# nice if we could, somehow.
rendered
=
self
.
schema
.
dump
(
event
)
# FIXME: transmit rendered over the underlying channel
pass
def
listen
(
self
,
callback
:
Callable
[[
Any
],
None
],
pattern
:
str
=
'
#
'
):
def
unwrapping_callback
(
message
):
event
=
self
.
schema
.
load
(
message
)
callback
(
event
)
# FIXME: ask the underlying channel to call us back
# but only for messages matching pattern
pass
def
__enter__
(
self
):
self
.
connect
()
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
close
()
# Predefined event channels for ease of use
workflow_events
=
Channel
(
WorkflowEventSchema
())
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