@@ -155,7 +155,7 @@ def add_scheduled_item(self, json_data, insert = False):
155
155
except :
156
156
exception ('Error adding scheduled item' )
157
157
except :
158
- exception ('AddScheduledItem failed ' )
158
+ exception ('Failed to add scheduled item ' )
159
159
return result
160
160
161
161
def update_scheduled_item (self , json_data ):
@@ -165,20 +165,20 @@ def update_scheduled_item(self, json_data):
165
165
debug ('Update scheduled item' )
166
166
result = False
167
167
try :
168
- scheduleItemNew = ScheduleItem (json_data )
168
+ new_item = ScheduleItem (json_data )
169
169
with self .mutex :
170
170
try :
171
- scheduleItemOld = self .schedules [scheduleItemNew .id ]
172
- schedule .cancel_job (scheduleItemOld .job )
171
+ old_item = self .schedules [new_item .id ]
172
+ schedule .cancel_job (old_item .job )
173
173
except KeyError :
174
- debug ('Old schedule with id = {} not found' .format (scheduleItemNew .id ))
175
- result = self .setup (scheduleItemNew )
174
+ debug ('Old schedule with id = {} not found' .format (new_item .id ))
175
+ result = self .setup (new_item )
176
176
debug ('Update scheduled item result: {}' .format (result ))
177
177
if result == True :
178
- self .update_database_item (dumps (json_data ), scheduleItemNew .id )
179
- self .schedules [scheduleItemNew .id ] = scheduleItemNew
178
+ self .update_database_item (dumps (json_data ), new_item .id )
179
+ self .schedules [new_item .id ] = new_item
180
180
except :
181
- exception ('UpdateScheduledItem failed ' )
181
+ exception ('Failed to update scheduled item ' )
182
182
return result
183
183
184
184
def setup (self , schedule_item ):
@@ -215,35 +215,33 @@ def process_action(self, schedule_item):
215
215
schedule_item: a ScheduleItem instance representing the item to process and run"""
216
216
debug ('' )
217
217
if schedule_item is None :
218
- error ('ProcessAction with empty schedule ' )
218
+ error ('No scheduled item to run ' )
219
219
return
220
220
# if schedule_item.job.should_run() == False:
221
221
# return
222
- statusSuccess = True
222
+ result = True
223
223
schedule_item .last_run = datetime .strftime (datetime .utcnow (), '%Y-%m-%d %H:%M' )
224
224
with self .mutex :
225
225
self .update_database_item (schedule_item .to_json (), schedule_item .id )
226
226
#TODO
227
227
#all this scheduler notification should be put in a db and if it was not possible to submit add a checker for sending notifications to cloud
228
228
#right now is a workaround in order to submit
229
- debug ('Notification: ' + str (schedule_item .notify ))
230
- if schedule_item .notify :
231
- body = 'Scheduler ' + schedule_item .title + ' ran with success: ' + str (statusSuccess ) + ' at UTC ' + str (datetime .utcnow ())
232
- subject = schedule_item .title
233
- #build an array of device names
234
- #if this fails to be sent, save it in the DB and resubmit it
235
- runStatus = False #self.client.SendNotification(schedule_item.notify, subject, body)
236
- sleep (1 )
237
- if runStatus == False :
238
- error ('Notification ' + str (schedule_item .notify ) + ' was not sent' )
229
+ # debug('Notification: ' + str(schedule_item.notify))
230
+ # if schedule_item.notify:
231
+ # body = 'Scheduler ' + schedule_item.title + ' ran with success: ' + str(status_success ) + ' at UTC ' + str(datetime.utcnow())
232
+ # subject = schedule_item.title
233
+ # #build an array of device names
234
+ # #if this fails to be sent, save it in the DB and resubmit it
235
+ # notified = False #self.client.SendNotification(schedule_item.notify, subject, body)
236
+ # sleep(1)
237
+ # if notified == False:
238
+ # error('Notification ' + str(schedule_item.notify) + ' was not sent')
239
239
for action in schedule_item .actions :
240
- #call cloudserver
241
- runStatus = self .client .RunAction (action )
242
- info ('Schedule executing action: ' + str (action ))
243
- if runStatus == False :
244
- error ('Action: ' + str (action ) + ' failed' )
245
- statusSuccess = False
246
- if schedule_item .type == 'date' and statusSuccess == True :
240
+ info ('Executing scheduled action: {}' .format (action ))
241
+ result = self .client .RunAction (action )
242
+ if result == False :
243
+ error ('Failed to execute action: {}' .format (action ))
244
+ if schedule_item .type == 'date' and result == True :
247
245
with self .mutex :
248
246
schedule .cancel_job (schedule_item .job )
249
247
0 commit comments