Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
176ff440
Commit
176ff440
authored
Dec 15, 2017
by
Lukas Burgey
Browse files
Change updating of clients after publishing
parent
001dd869
Changes
3
Show whitespace changes
Inline
Side-by-side
django_backend/backend/clientapi/models.py
View file @
176ff440
...
...
@@ -17,11 +17,13 @@ def publish_deployment(sender, instance=None, created=False, **kwargs):
message
=
json
.
dumps
(
DeploymentSerializer
(
instance
).
data
)
if
PubSubConnection
().
publish_by_service
(
instance
.
service
,
message
):
confirmed
,
online_sites
=
PubSubConnection
().
publish_by_service
(
instance
.
service
,
message
)
if
confirmed
:
# delivery successful
instance
.
service
.
site
.
client_updated
()
print
(
'Client got update for service {}'
.
format
(
instance
.
service
))
else
:
print
(
'Client failed to receive update for service {}'
.
format
(
instance
.
service
))
for
site
in
online_sites
:
print
(
'Client for site {} got update for service {}'
.
format
(
site
,
instance
.
service
,
))
site
.
client_updated
()
django_backend/backend/clientapi/pubsub.py
View file @
176ff440
...
...
@@ -34,26 +34,31 @@ class PubSubConnection:
def
service_routing_key
(
self
,
service
):
return
'service.'
+
service
.
name
def
is_client_connected
(
self
,
client
):
return
False
def
online_clients
(
self
,
service
):
rabbitmq
=
RabbitMQInstance
()
return
[
s
for
s
in
service
.
site
.
all
()
if
rabbitmq
.
is_client_connected
(
s
)]
def
publish_by_service
(
self
,
service
,
message
):
for
site
in
service
.
site
.
all
():
self
.
publish_by_service_and_site
(
service
,
site
,
message
)
def
publish_by_service_and_site
(
self
,
service
,
site
,
message
):
if
not
RabbitMQInstance
().
is_client_connected
(
site
):
print
(
'Client for site {} is not online'
.
format
(
site
))
return
False
print
(
'Client for site {} is online'
.
format
(
site
))
online_clients
=
self
.
online_clients
(
service
)
if
len
(
online_clients
)
>
0
:
print
(
"Online clients for service {}: {}"
.
format
(
service
,
online_clients
,
))
else
:
print
(
"No clients online for service {}"
.
format
(
service
))
return
self
.
connect
()
print
(
'Sent deployment update for service {}
sent to client of site {}'
.
format
(
service
,
site
)
)
print
(
'Sent deployment update for service {}
'
.
format
(
service
)
)
# True if the client acked the message
# True if
all
the client
s
acked the message
delivery_confirmed
=
self
.
channel
.
basic_publish
(
exchange
=
self
.
exchange_name
,
routing_key
=
self
.
service_routing_key
(
service
),
...
...
@@ -62,4 +67,4 @@ class PubSubConnection:
)
self
.
disconnect
()
return
delivery_confirmed
return
delivery_confirmed
,
online_clients
django_backend/backend/models.py
View file @
176ff440
...
...
@@ -66,7 +66,7 @@ class Site(models.Model):
return
self
.
name
def
client_updated
(
self
):
print
(
"Client
o
f site {} got updated"
.
format
(
self
.
name
))
print
(
"Client f
or
site {} got updated"
.
format
(
self
.
name
))
self
.
last_fetch
=
make_aware
(
datetime
.
now
())
self
.
save
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment