def deserialize(d): task = hxtool_scheduler_task( d['profile_id'], d['name'], task_id=d['task_id'], parent_id=d.get('parent_id', None), wait_for_parent=d.get('wait_for_parent', True), start_time=HXAPI.dt_from_str(d['start_time']), end_time=HXAPI.dt_from_str(d['end_time']) if d['end_time'] else None, next_run=HXAPI.dt_from_str(d['next_run']) if d['next_run'] else None, enabled=d['enabled'], immutable=d['immutable'], stop_on_fail=d['stop_on_fail'], defer_interval=d['defer_interval']) task.last_run = HXAPI.dt_from_str( d['last_run']) if d['last_run'] else None task.parent_complete = d.get('parent_complete', False) task.last_run_state = d.get('last_run_state', None) task.state = d.get('state') schedule = d.get('schedule', None) if schedule is dict: task.set_schedule(**schedule) task._calculate_next_run() for s in d['steps']: # I hate this step_module = eval(s['module']) task.add_step(step_module, s['function'], s['args'], s['kwargs']) return task
def parse_schedule(request_params): start_time = None schedule = None schedule_type = request_params.get('schedule', None) if schedule_type: if schedule_type == "run_at": start_time = HXAPI.dt_from_str(request_params['run_at_value']) elif schedule_type == "run_interval": schedule = {} interval_value = int(request_params['interval_value']) interval_unit = request_params['interval_unit'] if interval_unit == "second": schedule['seconds'] = interval_value elif interval_unit == "minute": schedule['minutes'] = interval_value elif interval_unit == "hour": schedule['hours'] = interval_value elif interval_unit == "day": schedule['days'] = interval_value elif interval_unit == "week": schedule['weeks'] = interval_value elif interval_unit == "month": schedule['months'] = interval_value if request_params['interval_start'] == "interval_start_at": start_time = HXAPI.dt_from_str( request_params['interval_start_value']) return (start_time, schedule)