Skip to content

Commit 5211355

Browse files
committed
update
1 parent ec3a8ca commit 5211355

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

scheduler/app/faas_scheduler/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def call_faas_func(script_url, temp_api_token, context_data, script_id=None):
172172
},
173173
"context_data": context_data,
174174
"script_id": script_id,
175+
"timeout": int(SUB_PROCESS_TIMEOUT)
175176
}
176177
headers = {"User-Agent": "python-scheduler/" + VERSION}
177178
logger.debug("I call starter at url %s", RUN_FUNC_URL)

scheduler/app/flask_server.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
uuid_str_to_32_chars,
2424
basic_log,
2525
)
26-
from .scheduler import scheduler
26+
from scheduler import scheduler
2727

2828

2929
basic_log("scheduler.log")
@@ -134,15 +134,15 @@ def script_api(script_id):
134134
if dtable_uuid != script.dtable_uuid or script_name != script.script_name:
135135
return make_response(("Bad request", 400))
136136

137-
# if SUB_PROCESS_TIMEOUT and isinstance(SUB_PROCESS_TIMEOUT, int):
138-
# now = datetime.now()
139-
# duration_seconds = (now - script.started_at).seconds
140-
# if duration_seconds > SUB_PROCESS_TIMEOUT:
141-
# script.success = False
142-
# script.return_code = -1
143-
# script.finished_at = now
144-
# script.output = TIMEOUT_OUTPUT
145-
# db_session.commit()
137+
if SUB_PROCESS_TIMEOUT and isinstance(SUB_PROCESS_TIMEOUT, int):
138+
now = datetime.now()
139+
duration_seconds = (now - script.started_at).seconds
140+
if duration_seconds > SUB_PROCESS_TIMEOUT:
141+
script.success = False
142+
script.return_code = -1
143+
script.finished_at = now
144+
script.output = TIMEOUT_OUTPUT
145+
db_session.commit()
146146

147147
return make_response(({"script": script.to_dict()}, 200))
148148

@@ -375,5 +375,6 @@ def base_run_python_statistics():
375375

376376

377377
if __name__ == "__main__":
378+
scheduler.start()
378379
http_server = WSGIServer(("127.0.0.1", 5055), app)
379380
http_server.serve_forever()

scheduler/app/scheduler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def __init__(self):
3030
# "<team>_<dtable_uuid>_<script_name>": 0
3131
# }
3232
try:
33-
run_limit_per_team = os.environ.get('RUN_LIMIT_PER_TEAM', 0)
33+
run_limit_per_team = int(os.environ.get('RUN_LIMIT_PER_TEAM', 0))
3434
except:
3535
run_limit_per_team = 0
3636
try:
37-
run_limit_per_base = os.environ.get('RUN_LIMIT_PER_BASE', 0)
37+
run_limit_per_base = int(os.environ.get('RUN_LIMIT_PER_BASE', 0))
3838
except:
3939
run_limit_per_base = 0
4040
try:
41-
run_limit_per_script = os.environ.get('RUN_LIMIT_PER_SCRIPT', 0)
41+
run_limit_per_script = int(os.environ.get('RUN_LIMIT_PER_SCRIPT', 0))
4242
except:
4343
run_limit_per_script = 0
4444
self.config = {
@@ -135,10 +135,11 @@ def schedule(self):
135135
script_log = self.script_queue.get()
136136
if not script_log:
137137
time.sleep(0.5)
138+
continue
138139
try:
139140
script_file_info = get_script_file(script_log.dtable_uuid, script_log.script_name)
140141
run_script(
141-
script_log.script_id,
142+
script_log.id,
142143
script_log.dtable_uuid,
143144
script_log.script_name,
144145
script_file_info['script_url'],

starter/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,4 @@ def health_check():
459459

460460

461461
if __name__ == "__main__":
462-
app.run(port=8088, debug=False)
462+
app.run(host='0.0.0.0', port=8088, debug=False)

0 commit comments

Comments
 (0)