@@ -162,24 +162,24 @@ def create_job(self, schedule_item):
162
162
debug ('Create job: {}' .format (schedule_item ))
163
163
try :
164
164
with self .mutex :
165
- event = schedule_item ['event' ]
166
- if event ['type' ] == 'date' :
167
- schedule_item ['job' ] = schedule .once ().at (event ['start_date' ])
168
- if event ['type' ] == 'interval' :
169
- if event ['unit' ] == 'hour' :
170
- schedule_item ['job' ] = schedule .every (event ['interval' ], event ['start_date' ]).hours
171
- if event ['unit' ] == 'minute' :
172
- schedule_item ['job' ] = schedule .every (event ['interval' ], event ['start_date' ]).minutes
173
- if event ['unit' ] == 'day' :
174
- schedule_item ['job' ] = schedule .every (event ['interval' ], event ['start_date' ]).days .at (event ['start_date' ])
175
- if event ['unit' ] == 'week' :
176
- schedule_item ['job' ] = schedule .every (event ['interval' ], event ['start_date' ]).weeks .at (event ['start_date' ])
177
- if event ['unit' ] == 'month' :
178
- schedule_item ['job' ] = schedule .every (event ['interval' ], event ['start_date' ]).months .at (event ['start_date' ])
179
- if event ['unit' ] == 'year' :
180
- schedule_item ['job' ] = schedule .every (event ['interval' ], event ['start_date' ]).years .at (event ['start_date' ])
181
- if 'last_run' in event :
182
- schedule_item ['job' ].set_last_run (event ['last_run' ])
165
+ config = schedule_item ['event' ][ 'config ' ]
166
+ if config ['type' ] == 'date' :
167
+ schedule_item ['job' ] = schedule .once ().at (config ['start_date' ])
168
+ if config ['type' ] == 'interval' :
169
+ if config ['unit' ] == 'hour' :
170
+ schedule_item ['job' ] = schedule .every (config ['interval' ], config ['start_date' ]).hours
171
+ if config ['unit' ] == 'minute' :
172
+ schedule_item ['job' ] = schedule .every (config ['interval' ], config ['start_date' ]).minutes
173
+ if config ['unit' ] == 'day' :
174
+ schedule_item ['job' ] = schedule .every (config ['interval' ], config ['start_date' ]).days .at (config ['start_date' ])
175
+ if config ['unit' ] == 'week' :
176
+ schedule_item ['job' ] = schedule .every (config ['interval' ], config ['start_date' ]).weeks .at (config ['start_date' ])
177
+ if config ['unit' ] == 'month' :
178
+ schedule_item ['job' ] = schedule .every (config ['interval' ], config ['start_date' ]).months .at (config ['start_date' ])
179
+ if config ['unit' ] == 'year' :
180
+ schedule_item ['job' ] = schedule .every (config ['interval' ], config ['start_date' ]).years .at (config ['start_date' ])
181
+ if 'last_run' in config :
182
+ schedule_item ['job' ].set_last_run (config ['last_run' ])
183
183
schedule_item ['job' ].do (self .run_scheduled_item , schedule_item )
184
184
except :
185
185
exception ('Failed setting up scheduler' )
@@ -196,15 +196,16 @@ def run_scheduled_item(self, schedule_item):
196
196
return
197
197
result = True
198
198
event = schedule_item ['event' ]
199
- event ['last_run' ] = datetime .strftime (datetime .utcnow (), '%Y-%m-%d %H:%M' )
199
+ config = event ['config' ]
200
+ config ['last_run' ] = datetime .strftime (datetime .utcnow (), '%Y-%m-%d %H:%M' )
200
201
with self .mutex :
201
202
self .update_database_record (event ['id' ], event )
202
203
for action in event ['actions' ]:
203
204
info ('Executing scheduled action: {}' .format (action ))
204
205
result = self .client .RunAction (action )
205
206
if result == False :
206
207
error ('Failed to execute action: {}' .format (action ))
207
- if event ['type' ] == 'date' and result == True :
208
+ if config ['type' ] == 'date' and result == True :
208
209
with self .mutex :
209
210
schedule .cancel_job (schedule_item ['job' ])
210
211
0 commit comments