Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DBE-DS-Group1-WS24
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robin Leber
DBE-DS-Group1-WS24
Commits
7e6a3718
Commit
7e6a3718
authored
1 year ago
by
Quoc Nguyen Dao
Browse files
Options
Downloads
Patches
Plain Diff
heartbeat fix
parent
45ab9012
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
server.py
+13
-8
13 additions, 8 deletions
server.py
with
13 additions
and
8 deletions
server.py
+
13
−
8
View file @
7e6a3718
...
...
@@ -305,15 +305,20 @@ class Server():
time
.
sleep
(
self
.
heartbeat_interval
)
def
heartbeat_subscriber
(
self
,
multicast_socket
):
multicast_socket
.
settimeout
(
3
)
while
True
:
data
,
address
=
multicast_socket
.
recvfrom
(
1024
)
if
data
:
self
.
leader_heartbeat_last_received
=
time
.
time
()
sender_ip
=
address
[
0
]
if
sender_ip
!=
MY_IP
:
print
(
f
"
Received heartbeat from
{
sender_ip
}
:
{
data
.
decode
()
}
"
)
try
:
data
,
address
=
multicast_socket
.
recvfrom
(
1024
)
if
data
:
self
.
leader_heartbeat_last_received
=
time
.
time
()
sender_ip
=
address
[
0
]
if
sender_ip
!=
MY_IP
:
print
(
f
"
Received heartbeat from
{
sender_ip
}
:
{
data
.
decode
()
}
"
)
else
:
# Wenn kein Heartbeat empfangen wurde
except
socket
.
timeout
:
time_since_last_heartbeat
=
time
.
time
()
-
self
.
leader_heartbeat_last_received
if
time_since_last_heartbeat
>
self
.
heartbeat_interval
:
self
.
missed_heartbeats
+=
1
...
...
@@ -328,7 +333,7 @@ class Server():
self
.
missed_heartbeats
=
0
# Code to initiate a new voting process to elect a new leader
# This could involve calling a function from voting.py or similar logic
time
.
sleep
(
self
.
heartbeat_interval
)
time
.
sleep
(
self
.
heartbeat_interval
)
# starting all simultaneously working procedures
...
...
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