Skip to content

Commit 0940ed0

Browse files
authored
Merge pull request #64 from omegaup/juan/11-13-Increase_timeout_in_deploy_request
Increase timeout in deploy request
2 parents a774a6b + 5deef0f commit 0940ed0

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

upload.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python3
22
import argparse
3+
import datetime
34
import json
45
import logging
56
import os
@@ -57,9 +58,14 @@ def _recursiveAdd(directory: str) -> None:
5758
_recursiveAdd(directory)
5859

5960

60-
def uploadProblemZip(client: omegaup.api.Client,
61-
problemConfig: Mapping[str, Any], canCreate: bool,
62-
zipPath: str, commitMessage: str) -> None:
61+
def uploadProblemZip(
62+
client: omegaup.api.Client,
63+
problemConfig: Mapping[str, Any],
64+
canCreate: bool,
65+
zipPath: str,
66+
commitMessage: str,
67+
timeout: datetime.timedelta,
68+
) -> None:
6369
"""Uploads a problem with the given .zip and configuration."""
6470
misc = problemConfig['misc']
6571
alias = misc['alias']
@@ -129,7 +135,7 @@ def uploadProblemZip(client: omegaup.api.Client,
129135

130136
files = {'problem_contents': open(zipPath, 'rb')}
131137

132-
client.query(endpoint, payload, files)
138+
client.query(endpoint, payload, files, timeout)
133139

134140
targetAdmins = misc.get('admins', [])
135141
targetAdminGroups = misc.get('admin-groups', [])
@@ -203,8 +209,13 @@ def uploadProblemZip(client: omegaup.api.Client,
203209
public=payload.get('public', False))
204210

205211

206-
def uploadProblem(client: omegaup.api.Client, problemPath: str,
207-
commitMessage: str, canCreate: bool) -> None:
212+
def uploadProblem(
213+
client: omegaup.api.Client,
214+
problemPath: str,
215+
commitMessage: str,
216+
canCreate: bool,
217+
timeout: datetime.timedelta,
218+
) -> None:
208219
with open(os.path.join(problemPath, 'settings.json'), 'r') as f:
209220
problemConfig = json.load(f)
210221

@@ -217,7 +228,8 @@ def uploadProblem(client: omegaup.api.Client, problemPath: str,
217228
problemConfig,
218229
canCreate,
219230
tempFile.name,
220-
commitMessage=commitMessage)
231+
commitMessage=commitMessage,
232+
timeout=timeout)
221233

222234
logging.info('Success uploading %s', problemConfig['title'])
223235

@@ -259,6 +271,10 @@ def _main() -> None:
259271
action='store_true',
260272
help=("Whether it's allowable to create the "
261273
"problem if it does not exist."))
274+
parser.add_argument("--timeout",
275+
type=int,
276+
default=60,
277+
help="Timeout for deploy API call (in seconds)")
262278
parser.add_argument('problem_paths',
263279
metavar='PROBLEM',
264280
type=str,
@@ -289,7 +305,8 @@ def _main() -> None:
289305
client,
290306
os.path.join(rootDirectory, problem.path),
291307
commitMessage=f'Deployed automatically from commit {commit}',
292-
canCreate=args.can_create)
308+
canCreate=args.can_create,
309+
timeout=datetime.timedelta(seconds=args.timeout))
293310

294311

295312
if __name__ == '__main__':

0 commit comments

Comments
 (0)