Skip to content

Commit 96eb53c

Browse files
committed
Run scheduled actions when agent is disconnected.
1 parent 22b0ea8 commit 96eb53c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

myDevices/cloud/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def __init__(self, host, port, cayenneApiHost):
268268
self.installDate = int(time())
269269
self.config.set('Agent', 'InstallDate', self.installDate)
270270
self.networkConfig = Config(NETWORK_SETTINGS)
271+
self.sensorsClient = sensors.SensorsClient()
271272
self.schedulerEngine = SchedulerEngine(self, 'client_scheduler')
272273
self.Initialize()
273274
self.CheckSubscription()
@@ -301,7 +302,6 @@ def Initialize(self):
301302
self.count = 10000
302303
self.buff = bytearray(self.count)
303304
#start thread only after init of other fields
304-
self.sensorsClient = sensors.SensorsClient()
305305
self.sensorsClient.SetDataChanged(self.OnDataChanged, self.BuildPT_SYSTEM_INFO)
306306
self.processManager = services.ProcessManager()
307307
self.serviceManager = services.ServiceManager()
@@ -471,6 +471,7 @@ def CheckSubscription(self):
471471
info('Registration succeeded for invite code {}, auth id = {}'.format(inviteCode, authId))
472472
self.config.set('Agent', 'Initialized', 'true')
473473
self.MachineId = authId
474+
self.config.set('Agent', 'Id', self.MachineId)
474475

475476
@property
476477
def Start(self):
@@ -622,9 +623,12 @@ def ReadMessage(self):
622623
def RunAction(self, action):
623624
"""Run a specified action"""
624625
debug('RunAction')
625-
if 'MachineName' in action and self.MachineId != action['MachineName']:
626-
debug('Scheduler action is not assigned for this machine: ' + str(action))
627-
return
626+
if 'MachineName' in action:
627+
#Use the config file machine if self.MachineId has not been set yet due to connection issues
628+
machine_id = self.MachineId if self.MachineId else self.config.get('Agent', 'Id')
629+
if machine_id != action['MachineName']:
630+
debug('Scheduler action is not assigned for this machine: ' + str(action))
631+
return
628632
self.ExecuteMessage(action)
629633

630634
def SendNotification(self, notify, subject, body):

0 commit comments

Comments
 (0)