async def run(self, data: Module.ResultSet, *args, **kwargs): # Mark module's start ctx: Context = self.context log(self, ctx.timer, '- Start') # Access strings (results) from the previous modules src = [text.fn() for text in data.of(LambdaInterface)] # E.g. some IO operation (delay for example purposes) await asyncio.sleep(self.SLEEP_TIME) # Mark module's end log(self, ctx.timer, '- End') # Build output string and produce declared interface msg = '(' + ' + '.join(src) + (' = ' if len(src) else '') + f'{self.name})' return LambdaInterface(lambda: msg)
async def run(self, data: Module.ResultSet, *args, **kwargs): # Mark module's start ctx: Context = self.context log(self, ctx.timer, '- Start') # Access strings (results) from the previous modules src = [t.data for t in data.of(StringInterface)] # Add delay for example purposes # delay duration is taken from optional parameter `sleep` # and is 2 seconds by default (if the parameter is not provided) sleep(self.parameters.get('sleep', 2)) # Mark module's end log(self, ctx.timer, '- End') # Build output string and produce declared interface return StringInterface('(' + ' + '.join(src) + (' = ' if len(src) else '') + f'{self.name})')
def run(self, data: Module.ResultSet, request: Request): # Access context ctx: Context = self.context # Mark module's start log(self, ctx.timer, '- Start') # Access results from the previous modules # `src` is a list of strings text = [t.fn() for t in data.of(LambdaInterface)] src = [t.data for t in data.of(StringInterface)] + text # Some heavy computational operations for example sleep(self.SLEEP_TIME) # Mark module's end log(self, ctx.timer, '- End') # Produce declared interface return StringInterface(f'{ctx.prefix} (' + ' + '.join(src) + (' = ' if len(src) else '') + f'{self.name}) {request.value}')
def teardown(self): ctx: Context = self.context log(self, ctx.timer, '--- Teardown!')
def bootstrap(self): ctx: Context = self.context log(self, ctx.timer, '--- Created!') log(self, ctx.timer, f"- Threshold = {self.parameters['threshold']}")
async def teardown(self): ctx: Context = self.context log(self, ctx.timer, '--- Long...!') await asyncio.sleep(1) log(self, ctx.timer, '--- ...Teardown!')
def bootstrap(self): ctx: Context = self.context log(self, ctx.timer, '--- Created!')