Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coolamqp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
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
public
coolamqp
Commits
944e1804
Commit
944e1804
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
on_fail
parent
0c3334da
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-1
1 addition, 1 deletion
CHANGELOG.md
coolamqp/clustering/cluster.py
+8
-2
8 additions, 2 deletions
coolamqp/clustering/cluster.py
tests/test_clustering/test_things.py
+10
-1
10 additions, 1 deletion
tests/test_clustering/test_things.py
with
19 additions
and
4 deletions
CHANGELOG.md
+
1
−
1
View file @
944e1804
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
*
0.92:
*
0.92:
*
TBA
*
Added
`on_fail`
event handler - fired upon connection loss
*
v0.91:
*
v0.91:
*
removed annoying warnings
*
removed annoying warnings
...
...
This diff is collapsed.
Click to expand it.
coolamqp/clustering/cluster.py
+
8
−
2
View file @
944e1804
...
@@ -39,7 +39,8 @@ class Cluster(object):
...
@@ -39,7 +39,8 @@ class Cluster(object):
"""
"""
:param nodes: list of nodes, or a single node. For now, only one is supported.
:param nodes: list of nodes, or a single node. For now, only one is supported.
:type nodes: NodeDefinition instance or a list of NodeDefinition instances
:type nodes: NodeDefinition instance or a list of NodeDefinition instances
:param on_fail: callable/0 to call when connection fails. This is a one-shot
:param on_fail: callable/0 to call when connection fails in an
unclean way. This is a one-shot
:type on_fail: callable/0
:type on_fail: callable/0
"""
"""
from
coolamqp.objects
import
NodeDefinition
from
coolamqp.objects
import
NodeDefinition
...
@@ -175,7 +176,12 @@ class Cluster(object):
...
@@ -175,7 +176,12 @@ class Cluster(object):
self
.
snr
=
SingleNodeReconnector
(
self
.
node
,
self
.
attache_group
,
self
.
listener
)
self
.
snr
=
SingleNodeReconnector
(
self
.
node
,
self
.
attache_group
,
self
.
listener
)
self
.
snr
.
on_fail
.
add
(
lambda
:
self
.
events
.
put_nowait
(
ConnectionLost
()))
self
.
snr
.
on_fail
.
add
(
lambda
:
self
.
events
.
put_nowait
(
ConnectionLost
()))
if
self
.
on_fail
is
not
None
:
if
self
.
on_fail
is
not
None
:
self
.
snr
.
on_fail
.
add
(
self
.
on_fail
)
def
nice
():
if
not
self
.
snr
.
terminating
:
self
.
on_fail
()
self
.
snr
.
on_fail
.
add
(
nice
)
# Spawn a transactional publisher and a noack publisher
# Spawn a transactional publisher and a noack publisher
self
.
pub_tr
=
Publisher
(
Publisher
.
MODE_CNPUB
)
self
.
pub_tr
=
Publisher
(
Publisher
.
MODE_CNPUB
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_clustering/test_things.py
+
10
−
1
View file @
944e1804
...
@@ -15,13 +15,22 @@ logging.basicConfig(level=logging.DEBUG)
...
@@ -15,13 +15,22 @@ logging.basicConfig(level=logging.DEBUG)
class
TestConnecting
(
unittest
.
TestCase
):
class
TestConnecting
(
unittest
.
TestCase
):
def
test_on_fail
(
self
):
def
test_on_fail
(
self
):
q
=
{}
q
=
{
'
failed
'
:
False
}
c
=
Cluster
([
NodeDefinition
(
'
127.0.0.1
'
,
'
xguest
'
,
'
xguest
'
,
heartbeat
=
20
)],
on_fail
=
lambda
:
q
.
update
(
failed
=
True
))
c
=
Cluster
([
NodeDefinition
(
'
127.0.0.1
'
,
'
xguest
'
,
'
xguest
'
,
heartbeat
=
20
)],
on_fail
=
lambda
:
q
.
update
(
failed
=
True
))
c
.
start
()
c
.
start
()
time
.
sleep
(
5
)
time
.
sleep
(
5
)
c
.
shutdown
()
c
.
shutdown
()
self
.
assertTrue
(
q
[
'
failed
'
])
self
.
assertTrue
(
q
[
'
failed
'
])
def
test_on_clean
(
self
):
q
=
{}
c
=
Cluster
([
NODE
],
on_fail
=
lambda
:
q
.
update
(
failed
=
True
))
c
.
start
()
time
.
sleep
(
5
)
c
.
shutdown
()
time
.
sleep
(
5
)
self
.
assertFalse
(
q
[
'
failed
'
])
def
test_start_called_multiple_times
(
self
):
def
test_start_called_multiple_times
(
self
):
c
=
Cluster
([
NODE
])
c
=
Cluster
([
NODE
])
c
.
start
(
wait
=
True
)
c
.
start
(
wait
=
True
)
...
...
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