Skip to content

Commit dbda4f7

Browse files
committed
update
1 parent cf3123b commit dbda4f7

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
@@ -170,6 +170,7 @@ def call_faas_func(script_url, temp_api_token, context_data, script_id=None):
170170
},
171171
"context_data": context_data,
172172
"script_id": script_id,
173+
"timeout": int(SUB_PROCESS_TIMEOUT)
173174
}
174175
headers = {"User-Agent": "python-scheduler/" + VERSION}
175176
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")
@@ -132,15 +132,15 @@ def script_api(script_id):
132132
if dtable_uuid != script.dtable_uuid or script_name != script.script_name:
133133
return make_response(("Bad request", 400))
134134

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

145145
return make_response(({"script": script.to_dict()}, 200))
146146

@@ -373,5 +373,6 @@ def base_run_python_statistics():
373373

374374

375375
if __name__ == "__main__":
376+
scheduler.start()
376377
http_server = WSGIServer(("127.0.0.1", 5055), app)
377378
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)