NubladoBusiness#

class mobu.services.business.nublado.NubladoBusiness(*, options, user, events, logger, flock)#

Bases: Business, Generic

Base class for business that executes Python code in a Nublado notebook.

This class modifies the core Business loop by providing startup, execute, and shutdown methods. It will log on to JupyterHub, ensure no lab currently exists, create a lab, call execute_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:

Methods Summary

close()

Clean up any allocated resources.

delete_lab()

dump()

execute()

Execute the core of each business loop.

execute_code(session)

Execute some code inside the Jupyter lab.

execution_idle()

Pause between each unit of work execution.

hub_login()

idle()

Pause at the end of each business loop.

lab_login()

open_session([notebook])

remove_ansi_escapes(string)

Remove ANSI escape sequences from a string.

setup_session(session)

shutdown()

Perform any cleanup required after stopping.

spawn_lab()

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:

None

async delete_lab()#
Return type:

None

dump()#
Return type:

NubladoBusinessData

async execute()#

Execute the core of each business loop.

Return type:

None

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:

None

async execution_idle()#

Pause between each unit of work execution.

This is not used directly by NubladoBusiness. It should be called by subclasses in execute_code in between each block of code that is executed.

Return type:

bool

async hub_login()#
Return type:

None

async idle()#

Pause at the end of each business loop.

Return type:

None

async lab_login()#
Return type:

None

open_session(notebook=None)#
Parameters:

notebook (str | None, default: None)

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.

Parameters:

string (str) – String to strip ANSI escapes from.

Returns:

Sanitized string.

Return type:

str

async setup_session(session)#
Parameters:

session (JupyterLabSession)

Return type:

None

async shutdown()#

Perform any cleanup required after stopping.

Return type:

None

async spawn_lab()#
Return type:

bool

async startup()#

Run before the start of the first iteration and then not again.

Return type:

None