Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
m_settings = get_model_settings()
m_version = get_worker_versions()
logging.info('register_worker: SUPPLIER_ID={}, MODEL_ID={}, VERSION_ID={}'.format(m_supplier, m_name, m_id))
signature(
'run_register_worker',
args=(m_supplier, m_name, m_id, m_settings, m_version),
queue='celery'
).delay()
class MissingInputsException(OasisException):
def __init__(self, input_archive):
super(MissingInputsException, self).__init__('Inputs location not found: {}'.format(input_archive))
class InvalidInputsException(OasisException):
def __init__(self, input_archive):
super(InvalidInputsException, self).__init__('Inputs location not a tarfile: {}'.format(input_archive))
class MissingModelDataException(OasisException):
def __init__(self, model_data_path):
super(MissingModelDataException, self).__init__('Model data not found: {}'.format(model_data_path))
@contextmanager
def get_lock():
lock = fasteners.InterProcessLock(settings.get('worker', 'LOCK_FILE'))
gotten = lock.acquire(blocking=False, timeout=settings.getfloat('worker', 'LOCK_TIMEOUT_IN_SECS'))
yield gotten
if gotten:
args=(m_supplier, m_name, m_id, m_settings, m_version),
queue='celery'
).delay()
class MissingInputsException(OasisException):
def __init__(self, input_archive):
super(MissingInputsException, self).__init__('Inputs location not found: {}'.format(input_archive))
class InvalidInputsException(OasisException):
def __init__(self, input_archive):
super(InvalidInputsException, self).__init__('Inputs location not a tarfile: {}'.format(input_archive))
class MissingModelDataException(OasisException):
def __init__(self, model_data_path):
super(MissingModelDataException, self).__init__('Model data not found: {}'.format(model_data_path))
@contextmanager
def get_lock():
lock = fasteners.InterProcessLock(settings.get('worker', 'LOCK_FILE'))
gotten = lock.acquire(blocking=False, timeout=settings.getfloat('worker', 'LOCK_TIMEOUT_IN_SECS'))
yield gotten
if gotten:
lock.release()
def get_oasislmf_config_path(model_id):
conf_var = settings.get('worker', 'oasislmf_config', fallback=None)
def run(analysis_settings, number_of_processes=-1):
if number_of_processes == -1:
number_of_processes = multiprocessing.cpu_count()
genbash(number_of_processes, analysis_settings, 'run_ktools.sh')
try:
subprocess.check_call(['bash', 'run_ktools.sh'])
except subprocess.CalledProcessError as e:
raise OasisException('Error running ktools: {}'.format(e.stderr))
@worker_ready.connect
def register_worker(sender, **k):
m_supplier = os.environ.get('OASIS_MODEL_SUPPLIER_ID')
m_name = os.environ.get('OASIS_MODEL_ID')
m_id = os.environ.get('OASIS_MODEL_VERSION_ID')
m_settings = get_model_settings()
m_version = get_worker_versions()
logging.info('register_worker: SUPPLIER_ID={}, MODEL_ID={}, VERSION_ID={}'.format(m_supplier, m_name, m_id))
signature(
'run_register_worker',
args=(m_supplier, m_name, m_id, m_settings, m_version),
queue='celery'
).delay()
class MissingInputsException(OasisException):
def __init__(self, input_archive):
super(MissingInputsException, self).__init__('Inputs location not found: {}'.format(input_archive))
class InvalidInputsException(OasisException):
def __init__(self, input_archive):
super(InvalidInputsException, self).__init__('Inputs location not a tarfile: {}'.format(input_archive))
class MissingModelDataException(OasisException):
def __init__(self, model_data_path):
super(MissingModelDataException, self).__init__('Model data not found: {}'.format(model_data_path))
@contextmanager
def get_lock():