in src/worker/jobUpdate/updateJobID.py [0:0]
def updateShm(self, data, device):
self.job_config[device]["lock"].acquire()
try:
config, currentSize = self.getCurrentJobConfig(device)
for dev_name in data[device]:
# device name is not being requested/it is
# not in the users config to be updated
if dev_name not in config[device].keys():
logging.debug("key mismatch on %s devices %s",
device, dev_name)
continue
# Update device name to user specified ID
if config[device][dev_name] is None:
config[device][dev_name] = data[device][dev_name]
config["Updated"] = 1
logging.debug("update job id on %s devices, data %s ",
device, data[device][dev_name])
# User requested update but device has another ID on it. Must
# be set to none before an update.
elif data[device][dev_name] is None:
config[device][dev_name] = None
config["Updated"] = 1
logging.debug("Resetting job id on %s devices", device)
# raise exception if ID for device is not None.
# We do not want to overwrite another job
else:
logging.debug("Exception raised", device)
raise Exception(
"Failed to update job. Devices are set to a job Id. \
Need to be set to None first before new upodate.")
msg = json.dumps(config)
# check new size vs old size
msgSize = len(msg.encode("utf8"))
if msgSize != currentSize:
logging.debug("Resizing shared memory for %s devices", device)
self.job_config[device]["shm_mgr"].resize_shm(data=msg)
else:
logging.debug("Not resizing shmem for %s devices", device)
shm = self.job_config[device]["shm_mgr"].get_shm()
shm.buf[:msgSize] = bytes(msg, 'UTF-8')
finally:
self.job_config[device]["lock"].release()