def add_success(result): add_worked = result.content.values add_failed = result.content.failed if len(add_failed) > 0: return Either.Left( "Failed to add internal instruments") # Update successfully added items update_mappings(add_worked, prefix) # Kick off the next batch return batch_query(instr_type, prefix, remainder)
def get_success(result): get_found = result.content.values get_failed = result.content.failed # Update successfully found items update_mappings(get_found, prefix) if len(get_failed) > 0: if instr_type == "ClientInternal": # For un-mapped internal codes, we will try to add (upsert) # called if the upsert_instruments() succeeds def add_success(result): add_worked = result.content.values add_failed = result.content.failed if len(add_failed) > 0: return Either.Left( "Failed to add internal instruments") # Update successfully added items update_mappings(add_worked, prefix) # Kick off the next batch return batch_query(instr_type, prefix, remainder) # Create the upsert request from the failed items request = { k: api.models.InstrumentDefinition( name=v.id, identifiers={"ClientInternal": v.id}) for k, v in get_failed.items() } return api.call.upsert_instruments(request).bind( add_success) else: # Instruments are not mapped. Nothing we cando. return Either.Left( "Failed to locate instruments of type {}".format( instr_type)) else: # No failures, kick off the next batch return batch_query(instr_type, prefix, remainder)