async def create_step(self, id, step: Step): try: step.id = shortuuid.uuid() item = self._find_by_id(id) step.instance = FermentStep(self.cbpi, step.id, step.name, None, self._done) item.steps.append(step) self.save() return step except Exception as e: self.logger.error(e)
async def update(self, item: Step): logging.info("update step") try: type_cfg = self.types.get(item.type) clazz = type_cfg.get("class") item.instance = clazz(self.cbpi, item.id, item.name, item.props, self.done) except Exception as e: logging.warning("Failed to create step instance %s - %s " % (item.id, e)) item.instance = None self.profile = list(map(lambda old: item if old.id == item.id else old, self.profile)) await self.save() return item
async def add(self, item: Step): logging.debug("Add step") item.id = shortuuid.uuid() item.status = StepState.INITIAL try: type_cfg = self.types.get(item.type) clazz = type_cfg.get("class") item.instance = clazz(self.cbpi, item.id, item.name, item.props, self.done) except Exception as e: logging.warning("Failed to create step instance %s - %s " % (id, e)) item.instance = None self.profile.append(item) await self.save() return item
async def http_add(self, request): """ --- description: Add tags: - Step parameters: - in: body name: body description: Created an step required: true schema: type: object responses: "200": description: successful operation """ data = await request.json() step = Step(name=data.get("name"), props=Props(data.get("props", {})), type=data.get("type")) response_data = await self.controller.add(step) return web.json_response(data=response_data.to_dict())
def create(self, data): id = data.get("id") name = data.get("name") type = data.get("type") status = StepState(data.get("status", "I")) props = Props(data.get("props", {})) try: type_cfg = self.types.get(type) clazz = type_cfg.get("class") instance = clazz(self.cbpi, id, name, props, self.done) except Exception as e: logging.warning("Failed to create step instance %s - %s" % (id, e)) instance = None step=Step(id, name, type=type, status=status, instance=instance, props=props ) return step
async def http_update(self, request): """ --- description: Update tags: - Step parameters: - in: body name: body description: Created an kettle required: false schema: type: object responses: "200": description: successful operation """ data = await request.json() id = request.match_info['id'] step = Step(id, data.get("name"), Props(data.get("props", {})), data.get("type")) return web.json_response((await self.controller.update(step)).to_dict())