Skip to content

Commit

Permalink
Fix worker updates
Browse files Browse the repository at this point in the history
Releases the worker lock on update
  • Loading branch information
Viren6 committed Aug 17, 2024
1 parent 1e87a8c commit c745cfe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/montytest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
according to the route/URL mapping defined in `__init__.py`.
"""

WORKER_VERSION = 11
WORKER_VERSION = 12


@exception_view_config(HTTPException)
Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 11, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "5H/vhWvrKp34ehp12ppQWXr0lYOQT1lHs8qjHg2XX02oLHZtMkO9iyK1IgVCwVqa", "games.py": "SOlAX95oLMYwCKNm/XkK5Uf1WPw1PGeIPzvgZqZ04AHNF2+MQ1vc+blTGu5F0JUZ"}
{"__version": 12, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "0fvv6AahgRpu9pjF/xgjdVWjRujuecreJJ9Pyw8yyqfLY8aQ+nhZQlLll4/fWj/k", "games.py": "SOlAX95oLMYwCKNm/XkK5Uf1WPw1PGeIPzvgZqZ04AHNF2+MQ1vc+blTGu5F0JUZ"}
16 changes: 12 additions & 4 deletions worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
MIN_CARGO_MAJOR = 1
MIN_CARGO_MINOR = 77

WORKER_VERSION = 11
WORKER_VERSION = 12
FILE_LIST = ["updater.py", "worker.py", "games.py"]
HTTP_TIMEOUT = 30.0
INITIAL_RETRY_TIME = 15.0
Expand Down Expand Up @@ -1172,7 +1172,7 @@ def utcoffset():
return "{}{:02d}:{:02d}".format("+" if utcoffset >= 0 else "-", hh, mm)


def verify_worker_version(remote, username, password):
def verify_worker_version(remote, username, password, worker_lock):
# Returns:
# True: we are the right version and have the correct credentials
# False: incorrect credentials (the user may have been blocked in the meantime)
Expand All @@ -1191,6 +1191,7 @@ def verify_worker_version(remote, username, password):
print("Updating worker version to {}".format(req["version"]))
backup_log()
try:
worker_lock.release()
update()
except Exception as e:
print(
Expand All @@ -1211,6 +1212,7 @@ def fetch_and_handle_task(
current_state,
clear_binaries,
global_cache,
worker_lock,
):
# This function should normally not raise exceptions.
# Unusual conditions are handled by returning False.
Expand All @@ -1225,7 +1227,7 @@ def fetch_and_handle_task(
)

# Check the worker version and upgrade if necessary
ret = verify_worker_version(remote, worker_info["username"], password)
ret = verify_worker_version(remote, worker_info["username"], password, worker_lock)
if ret is False:
current_state["alive"] = False
if not ret:
Expand Down Expand Up @@ -1464,7 +1466,12 @@ def worker():

# Check the worker version and upgrade if necessary
try:
if verify_worker_version(remote, options.username, options.password) is False:
if (
verify_worker_version(
remote, options.username, options.password, worker_lock
)
is False
):
return 1
except Exception as e:
print("Exception verifying worker version:\n", e, sep="", file=sys.stderr)
Expand Down Expand Up @@ -1562,6 +1569,7 @@ def worker():
current_state,
clear_binaries,
options.global_cache,
worker_lock,
)
if not current_state["alive"]: # the user may have pressed Ctrl-C...
break
Expand Down

0 comments on commit c745cfe

Please sign in to comment.