Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iotamak-core
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMAC
AMAK
Python
IoTAMAK
iotamak-core
Commits
226ac344
Commit
226ac344
authored
3 years ago
by
shinedday
Browse files
Options
Downloads
Patches
Plain Diff
Fix some waking up issue
parent
0fa0dd08
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
agent.py
+1
-5
1 addition, 5 deletions
agent.py
amas.py
+1
-5
1 addition, 5 deletions
amas.py
environment.py
+1
-5
1 addition, 5 deletions
environment.py
schedulable.py
+5
-1
5 additions, 1 deletion
schedulable.py
scheduler.py
+16
-10
16 additions, 10 deletions
scheduler.py
with
24 additions
and
26 deletions
agent.py
+
1
−
5
View file @
226ac344
...
...
@@ -12,7 +12,7 @@ class Agent(Schedulable):
Schedulable
.
__init__
(
self
,
client_id
=
"
Agent
"
+
str
(
self
.
id
))
self
.
subscribe
(
"
scheduler/agent/wakeup
"
,
self
.
scheduler_
wake_up
)
self
.
subscribe
(
"
scheduler/agent/wakeup
"
,
self
.
wake_up
)
self
.
neighbors
=
[]
self
.
next_neighbors
=
[]
...
...
@@ -41,10 +41,6 @@ class Agent(Schedulable):
def
publish
(
self
,
topic
:
str
,
message
)
->
None
:
self
.
client
.
publish
(
"
agent/
"
+
str
(
self
.
id
)
+
"
/
"
+
topic
,
message
)
def
scheduler_wake_up
(
self
,
client
,
userdata
,
message
):
self
.
wake_up_token
=
True
print
(
"
waked up
"
)
def
on_cycle_begin
(
self
):
self
.
log
(
"
on_cycle_begin
"
)
...
...
This diff is collapsed.
Click to expand it.
amas.py
+
1
−
5
View file @
226ac344
...
...
@@ -15,7 +15,7 @@ class Amas(Schedulable):
def
__init__
(
self
):
Schedulable
.
__init__
(
self
,
client_id
=
"
Amas
"
)
self
.
subscribe
(
"
scheduler/schedulable/wakeup
"
,
self
.
scheduler_
wake_up
)
self
.
subscribe
(
"
scheduler/schedulable/wakeup
"
,
self
.
wake_up
)
self
.
next_id
=
0
...
...
@@ -29,10 +29,6 @@ class Amas(Schedulable):
def
on_initial_agents_creation
(
self
):
pass
def
scheduler_wake_up
(
self
,
client
,
userdata
,
message
):
self
.
wake_up_token
=
True
print
(
"
waked up
"
)
def
add_agent
(
self
):
try
:
s
=
pxssh
.
pxssh
()
...
...
This diff is collapsed.
Click to expand it.
environment.py
+
1
−
5
View file @
226ac344
...
...
@@ -13,16 +13,12 @@ class Environment(Schedulable):
def
__init__
(
self
):
Schedulable
.
__init__
(
self
,
client_id
=
"
Env
"
)
self
.
subscribe
(
"
scheduler/schedulable/wakeup
"
,
self
.
scheduler_
wake_up
)
self
.
subscribe
(
"
scheduler/schedulable/wakeup
"
,
self
.
wake_up
)
self
.
on_initialization
()
self
.
client
.
publish
(
"
env/action_done
"
,
""
)
def
scheduler_wake_up
(
self
,
client
,
userdata
,
message
):
self
.
wake_up_token
=
True
print
(
"
waked up
"
)
def
on_initialization
(
self
)
->
None
:
"""
This method will be executed at the end of __init__()
...
...
This diff is collapsed.
Click to expand it.
schedulable.py
+
5
−
1
View file @
226ac344
...
...
@@ -21,9 +21,13 @@ class Schedulable(MqttClient):
self
.
wait_delay
:
float
=
0.01
self
.
wake_up_token
:
int
=
0
def
wake_up
(
self
,
client
,
userdata
,
message
):
self
.
wake_up_token
+=
1
print
(
"
Waked up
"
)
def
wait
(
self
):
# print("Waiting")
while
not
self
.
wake_up_token
>
1
:
while
self
.
wake_up_token
==
0
:
sleep
(
self
.
wait_delay
)
self
.
wake_up_token
-=
1
# print("End wait")
...
...
This diff is collapsed.
Click to expand it.
scheduler.py
+
16
−
10
View file @
226ac344
...
...
@@ -22,8 +22,6 @@ class Scheduler(Schedulable):
def
update_schedulable
(
self
,
client
,
userdata
,
message
):
self
.
schedulable_waiting
+=
1
if
self
.
schedulable_waiting
==
2
:
self
.
wake_up_token
+=
1
print
(
"
__Schedulable is waiting
"
)
def
update_nbr_agent
(
self
,
client
,
userdata
,
message
):
...
...
@@ -33,10 +31,18 @@ class Scheduler(Schedulable):
def
agent_done
(
self
,
client
,
userdata
,
message
):
self
.
agent_waiting
+=
1
if
self
.
agent_waiting
>=
self
.
nbr_agent
:
self
.
wake_up_token
+=
1
print
(
"
__Agent done
"
)
def
wait_agent
(
self
):
while
self
.
agent_waiting
<
self
.
nbr_agent
:
sleep
(
self
.
wait_delay
)
self
.
agent_waiting
=
0
def
wait_schedulable
(
self
):
while
self
.
schedulable_waiting
<
2
:
sleep
(
self
.
wait_delay
)
self
.
schedulable_waiting
=
0
def
first_part
(
self
)
->
None
:
"""
first part of a cycle
...
...
@@ -44,7 +50,7 @@ class Scheduler(Schedulable):
self
.
client
.
publish
(
"
scheduler/schedulable/wakeup
"
,
""
)
# Amas on cycle begin
# Environment on cycle begin
self
.
wait
()
self
.
wait
_schedulable
()
def
main_part
(
self
)
->
None
:
"""
...
...
@@ -52,10 +58,10 @@ class Scheduler(Schedulable):
"""
self
.
client
.
publish
(
"
scheduler/agent/wakeup
"
,
""
)
# Agent doing phase 1
self
.
wait
()
self
.
wait
_agent
()
self
.
client
.
publish
(
"
scheduler/agent/wakeup
"
,
""
)
# agent doing phase 2
self
.
wait
()
self
.
wait
_agent
()
def
last_part
(
self
)
->
None
:
"""
...
...
@@ -64,7 +70,7 @@ class Scheduler(Schedulable):
self
.
client
.
publish
(
"
scheduler/schedulable/wakeup
"
,
""
)
# Amas on cycle end
# Environment on cycle end
self
.
wait
()
self
.
wait
_schedulable
()
def
run
(
self
)
->
None
:
"""
...
...
@@ -73,10 +79,10 @@ class Scheduler(Schedulable):
# wait that all schedulable have init
print
(
"
Waiting schedulable
"
)
self
.
wait
()
self
.
wait
_schedulable
()
# Wait that all agent have init
print
(
"
Waiting agents :
"
,
self
.
nbr_agent
)
self
.
wait
()
self
.
wait
_agent
()
while
not
self
.
exit_bool
:
print
(
"
Cycle :
"
,
self
.
nbr_cycle
)
...
...
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