Skip to content

Commit

Permalink
agent-spawner: base64 encoding one more time
Browse files Browse the repository at this point in the history
The base64 encoding is worth doing on the dispatcher side, and store
strings to Redis, instead of decoding and encoding it once more in
worker (see #155).

Fixes: #155, #156
  • Loading branch information
praiskup committed Mar 14, 2024
1 parent 337b16d commit 2ea8ff7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions resalloc_agent_spawner/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Agent spawner daemon. Part of the resalloc project.
"""

import base64
import sys
import logging
from copr_common.dispatcher import Dispatcher
Expand Down Expand Up @@ -84,7 +85,11 @@ def get_ticket_data(self, ticket_id):
if not ticket.collect():
# not yet resolved or failed
return None
return ticket.output

# The ticket.output is bytes(), and we don't plan to touch the data at
# all, we are just going to "forward" the data base64 encoded to our
# hook scripts. Encode it now, and never change again.
return base64.b64encode(ticket.output).decode("ascii")

def try_to_stop(self, group_id, to_stop):
"""
Expand Down Expand Up @@ -174,10 +179,10 @@ def start_preparing(self):
resource that we can prepare (in the background). Switch the state.
"""
for ticket_id in self.get_tickets("NEW"):
ticket = self.resalloc.getTicket(ticket_id)
if not ticket.collect():
data = self.get_ticket_data(ticket_id)
if data is None:
continue
self.set_ticket_attribute(ticket_id, "data", ticket.output)
self.set_ticket_attribute(ticket_id, "data", data)
self.set_ticket_attribute(ticket_id, "state", "PREPARING")

def detect_failed_tickets(self):
Expand Down
6 changes: 3 additions & 3 deletions resalloc_agent_spawner/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
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 @@ -37,7 +35,9 @@ 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"])

# dispatcher already converted data to b64-encoded strings
ticket_data = redis_dict["data"]

if redis_dict["state"] == "PREPARING":
if self.cmd_take(redis_dict["group_id"], ticket_data):
Expand Down

0 comments on commit 2ea8ff7

Please sign in to comment.