def create(self, callback): assert self._callback is None self._callback = callback fruit = Fruit(fruit_id=uuid.uuid4().hex, fruit=Fruit.get_random_fruit()) ap = AsyncFruitPersister(fruit) ap.persist(self._on_persist_done)
def post(payload: Payload): try: if REDIS.get(f"{payload.name}"): raise Exception(f"Fruit {payload.name} already exists!") Fruit(**{"name": payload.name, "count": payload.count}).add() Fruit.commit() REDIS.set(f"{payload.name}", f"{payload.count}") return EnumResponse.OK.value.response except Exception as error: logger.warning(error) return EnumResponse.BAD_REQUEST.value.response
def _on_fetch_done(self, is_ok, fruit, afr): if not is_ok: self._call_callback(False) return if fruit is None: self._call_callback(True) return new_fruit = afr.async_state if not new_fruit: new_fruit = Fruit.get_random_fruit() fruit.change_fruit(new_fruit) afp = AsyncFruitPersister(fruit) afp.persist(self._on_persist_done)
def create_model_from_doc(self, doc): return Fruit(doc=doc)
def init_cache(): fruits: List[Fruit] = Fruit.query().all() for fruit in fruits: REDIS.set(fruit.name, f"{fruit.count}")
def clean_db(): Fruit.query().delete() Fruit.commit()
def init_cache(): fruits: List[Fruit] = Fruit.query().all() for fruit in fruits: REDIS.set(fruit.name, f"{fruit.count}") # Intended to trigger server error REDIS.set("error", "error")
def init_db(): Fruit(**{"name": "apple", "count": 1}).add() Fruit.commit()
def _random_item(): ITEMS = ( Shirt( name='Polo', description= 'Bacon ipsum dolor sit amet ham hock brisket ground round sirloin pork loin corned beef, pastrami ball tip venison pancetta filet mignon capicola tri-tip chuck. Ground round meatloaf prosciutto sausage, strip steak ball tip tenderloin andouille frankfurter pork ham short ribs hamburger bresaola. Hamburger rump filet mignon venison swine pork chop fatback. Capicola drumstick short loin, venison strip steak turkey chicken biltong turducken pork chop prosciutto pork jerky. Bacon sirloin flank, hamburger tri-tip drumstick ham hock pork loin pork chop.', price=49.99, size=Shirt.SMALL), Shirt( name='Oxford', description= 'Boudin beef meatloaf ham hock shank short loin sirloin salami filet mignon hamburger pig biltong spare ribs pork. Short ribs pork chop leberkas cow tail tongue strip steak capicola chuck andouille t-bone. Tenderloin brisket ham hock, strip steak pig tri-tip pastrami beef ham prosciutto turkey filet mignon. Jerky swine beef, frankfurter ribeye prosciutto sirloin sausage cow leberkas andouille chuck tongue ball tip. Shankle turkey boudin ball tip, hamburger rump biltong pork belly flank short ribs bresaola sirloin chicken kielbasa. Swine pancetta pastrami meatball frankfurter, chicken flank. Drumstick beef ribs pork filet mignon.', price=59.99, size=Shirt.SMALL), Shirt( name='Graphic T', description= 'Pork loin kielbasa leberkas tongue ribeye meatball. Pancetta leberkas shoulder boudin shankle tongue. Pastrami shoulder strip steak fatback andouille rump flank pork chop drumstick jerky leberkas shankle. Pork loin cow pork chop ground round frankfurter, ham boudin ribeye turkey beef ribs prosciutto shankle meatball sirloin meatloaf.', price=69.99, size=Shirt.SMALL), Shirt( name='Pocket T', description= 'Swine ball tip frankfurter, pancetta shankle flank spare ribs ribeye capicola cow pork chop fatback kielbasa andouille t-bone. Spare ribs ball tip leberkas, pastrami salami turducken andouille hamburger. Bresaola beef ribs filet mignon, sausage t-bone shoulder venison ribeye pancetta chuck. Andouille kielbasa tenderloin, spare ribs short ribs biltong jerky fatback.', price=100, size=Shirt.MEDIUM), Shirt( name='Muscle T', description= 'Turducken shoulder tail, bresaola kielbasa shank pork tri-tip flank brisket. Prosciutto chicken ground round, short loin brisket corned beef boudin cow. Fatback tail meatball spare ribs chicken. Salami cow strip steak tri-tip shankle shoulder tenderloin drumstick pig sirloin pork chop rump biltong hamburger ball tip.', price=150, size=Shirt.LARGE), Fruit( name='Apple', description= 'Bacon ipsum dolor sit amet ham hock brisket ground round sirloin pork loin corned beef, pastrami ball tip venison pancetta filet mignon capicola tri-tip chuck. Ground round meatloaf prosciutto sausage, strip steak ball tip tenderloin andouille frankfurter pork ham short ribs hamburger bresaola. Hamburger rump filet mignon venison swine pork chop fatback. Capicola drumstick short loin, venison strip steak turkey chicken biltong turducken pork chop prosciutto pork jerky. Bacon sirloin flank, hamburger tri-tip drumstick ham hock pork loin pork chop.', price=1), Fruit( name='Banana', description= 'Boudin beef meatloaf ham hock shank short loin sirloin salami filet mignon hamburger pig biltong spare ribs pork. Short ribs pork chop leberkas cow tail tongue strip steak capicola chuck andouille t-bone. Tenderloin brisket ham hock, strip steak pig tri-tip pastrami beef ham prosciutto turkey filet mignon. Jerky swine beef, frankfurter ribeye prosciutto sirloin sausage cow leberkas andouille chuck tongue ball tip. Shankle turkey boudin ball tip, hamburger rump biltong pork belly flank short ribs bresaola sirloin chicken kielbasa. Swine pancetta pastrami meatball frankfurter, chicken flank. Drumstick beef ribs pork filet mignon.', price=2), Fruit( name='Grape', description= 'Pork loin kielbasa leberkas tongue ribeye meatball. Pancetta leberkas shoulder boudin shankle tongue. Pastrami shoulder strip steak fatback andouille rump flank pork chop drumstick jerky leberkas shankle. Pork loin cow pork chop ground round frankfurter, ham boudin ribeye turkey beef ribs prosciutto shankle meatball sirloin meatloaf.', price=3), Fruit( name='Orange', description= 'Swine ball tip frankfurter, pancetta shankle flank spare ribs ribeye capicola cow pork chop fatback kielbasa andouille t-bone. Spare ribs ball tip leberkas, pastrami salami turducken andouille hamburger. Bresaola beef ribs filet mignon, sausage t-bone shoulder venison ribeye pancetta chuck. Andouille kielbasa tenderloin, spare ribs short ribs biltong jerky fatback.', price=4), Fruit( name='Strawberry', description= 'Turducken shoulder tail, bresaola kielbasa shank pork tri-tip flank brisket. Prosciutto chicken ground round, short loin brisket corned beef boudin cow. Fatback tail meatball spare ribs chicken. Salami cow strip steak tri-tip shankle shoulder tenderloin drumstick pig sirloin pork chop rump biltong hamburger ball tip.', price=5), ) from random import choice return choice(ITEMS)