Skip to content

Commit 383943d

Browse files
committed
update ScriptLog.state correctly
1 parent a7b64f4 commit 383943d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

scheduler/app/faas_scheduler/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def __init__(
5454
self.script_name = script_name
5555
self.context_data = context_data
5656
self.started_at = started_at
57-
self.operate_from = operate_from
5857
self.state = state
58+
self.operate_from = operate_from
5959

6060
def get_info(self):
6161
return {

scheduler/app/faas_scheduler/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def add_script(
381381
script_name,
382382
context_data,
383383
datetime.now(),
384+
ScriptLog.PENDING,
384385
operate_from,
385386
)
386387
db_session.add(script)
@@ -394,6 +395,7 @@ def update_script(db_session, script, success, return_code, output):
394395
script.success = success
395396
script.return_code = return_code
396397
script.output = output
398+
script.state = ScriptLog.FINISHED
397399
db_session.commit()
398400

399401
return script

scheduler/app/scheduler.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,13 @@ def schedule(self):
200200
if not script_log:
201201
time.sleep(0.5)
202202
continue
203+
db_session = DBSession()
203204
try:
205+
db_session.query(ScriptLog).filter(ScriptLog.id==script_log.id).update(
206+
{ScriptLog.state: ScriptLog.RUNNING},
207+
synchronize_session=False
208+
)
209+
db_session.commit()
204210
script_file_info = get_script_file(script_log.dtable_uuid, script_log.script_name)
205211
run_script(
206212
script_log.id,
@@ -212,6 +218,8 @@ def schedule(self):
212218
)
213219
except Exception as e:
214220
logger.exception(f'run script: {script_log} error {e}')
221+
finally:
222+
DBSession.remove()
215223

216224
def script_done_callback(
217225
self,
@@ -255,7 +263,8 @@ def timeout_setter(self):
255263
ScriptLog.success: False,
256264
ScriptLog.output: TIMEOUT_OUTPUT,
257265
ScriptLog.return_code: -1
258-
}
266+
},
267+
synchronize_session=False
259268
)
260269
except Exception as e:
261270
logger.exception(e)
@@ -271,6 +280,8 @@ def statistic_cleaner(self):
271280
delete_statistics_after_days(db_session)
272281
except Exception as e:
273282
logger.exception(e)
283+
finally:
284+
DBSession.remove()
274285
time.sleep(24 * 60 * 60)
275286

276287
def start(self):

0 commit comments

Comments
 (0)