Skip to content

Commit

Permalink
agent-spawner: base64 encode the resalloc ticket DATA in env
Browse files Browse the repository at this point in the history
Fixes: #144
  • Loading branch information
praiskup committed Feb 27, 2024
1 parent 36a289d commit 41e7132
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions config/agent-spawner/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
# # agent immediately marked for removal. `cmd_terminate` exit status is
# # just ignored (we need to remove the agent no matter what).
#
# # Prepare the agent. Variable $RESALLOC_RESOURCE_DATA (base64 encoded)
# # is provided in the script environment. Other variables like
# # RESOURCE_NAME, RESOURCE_POOL_ID, etc. are provided as well.
# # Prepare the agent. Variable $AGENT_SPAWNER_RESOURCE_DATA (base64
# # encoded, output from `resalloc ticket-wait`) is provided in the script
# # environment.
# cmd_prepare: /bin/true
#
# # Prepare the agent for termination. Upon finishing this command, the
# # resalloc resource ticket is closed and the resource deallocated.
# # resalloc resource ticket is closed and the resource deallocated (the
# # $AGENT_SPAWNER_RESOURCE_DATA env var is provided as well).
# cmd_terminate: echo noop
#
# # The following commands are executed synchronously by the agent spawner
Expand Down
8 changes: 6 additions & 2 deletions resalloc_agent_spawner/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Handle certain tasks by a background daemon process.
"""

import base64

from copr_common.background_worker import BackgroundWorker

from resalloc_agent_spawner.helpers import (
Expand Down Expand Up @@ -35,16 +37,18 @@ def handle_ticket(self, ticket_id):
# We know there's self._redis initialized by parent class so we don't
# create yet another connection.
redis_dict = self._redis.hgetall(redis_key)
ticket_data = base64.b64encode(redis_dict["data"])

if redis_dict["state"] == "PREPARING":
if self.cmd_take(redis_dict["group_id"], redis_dict["data"]):
if self.cmd_take(redis_dict["group_id"], ticket_data):
self._redis.hset(redis_key, "state", "WORKING")
else:
# failed preparation -> prepare removal
self._redis.hset(redis_key, "state", "ENDED")
return

if redis_dict["state"] == "TERMINATING":
self.cmd_terminate(redis_dict["group_id"], redis_dict["data"])
self.cmd_terminate(redis_dict["group_id"], ticket_data)
self._redis.hset(redis_key, "state", "ENDED")

def handle_task(self):
Expand Down

0 comments on commit 41e7132

Please sign in to comment.