NubladoBusiness#
- class mobu.services.business.nublado.NubladoBusiness(*, options, user, events, logger, flock)#
-
Base class for business that executes Python code in a Nublado notebook.
This class modifies the core
Business
loop by providingstartup
,execute
, andshutdown
methods. It will log on to JupyterHub, ensure no lab currently exists, create a lab, callexecute_code
, and then optionally shut down the lab before starting another iteration.Subclasses must override
execute_code
to do whatever they want to do inside a lab.Once this business has been stopped, it cannot be started again (the
aiohttp.ClientSession
will be closed), and the instance should be dropped after retrieving any wanted status information.- Parameters:
options (
TypeVar
(T
, bound=NubladoBusinessOptions
)) – Configuration options for the business.user (
AuthenticatedUser
) – User with their authentication token to use to run the business.events (
Events
) – Event publishers.logger (
BoundLogger
) – Logger to use to report the results of business.
Methods Summary
close
()Clean up any allocated resources.
dump
()execute
()Execute the core of each business loop.
execute_code
(session)Execute some code inside the Jupyter lab.
Pause between each unit of work execution.
idle
()Pause at the end of each business loop.
open_session
([notebook])remove_ansi_escapes
(string)Remove ANSI escape sequences from a string.
setup_session
(session)shutdown
()Perform any cleanup required after stopping.
startup
()Run before the start of the first iteration and then not again.
Methods Documentation
- async close()#
Clean up any allocated resources.
This should be overridden by child classes to free any resources that were allocated in
__init__
.- Return type:
- dump()#
- Return type:
- abstract async execute_code(session)#
Execute some code inside the Jupyter lab.
Must be overridden by subclasses to use the provided lab session to perform whatever operations are desired inside the lab. If multiple blocks of code are being executed, call
execution_idle
between each one.- Parameters:
session (
JupyterLabSession
) – Authenticated session to the Nublado lab.- Return type:
- async execution_idle()#
Pause between each unit of work execution.
This is not used directly by
NubladoBusiness
. It should be called by subclasses inexecute_code
in between each block of code that is executed.- Return type:
- open_session(notebook=None)#
- Parameters:
- Return type:
AsyncGenerator
[JupyterLabSession
]
- remove_ansi_escapes(string)#
Remove ANSI escape sequences from a string.
Jupyter labs like to format error messages with lots of ANSI escape sequences, and Slack doesn’t like that in messages (nor do humans want to see them). Strip them out.
Based on this StackOverflow answer.