MicroStrategy / mstrio-py

Python integration for MicroStrategy
Apache License 2.0
90 stars 59 forks source link

Check if Job failed? #194

Open rickymedrano opened 3 months ago

rickymedrano commented 3 months ago

Hi, how would it be possible to know if a Job failed? Specifically, I'm refreshing a cube with:

def refresh_cube(conn, cube_id) -> str:
    # Get cube object
    cube = OlapCube(connection=conn, id=cube_id)
    # Refresh cube
    job = cube.publish()
    # Give API enough time to register publish request
    time.sleep(5)
    # Get the latest status of the cube
    cube.refresh_status()
    tic = time.perf_counter()
    # Keep checking the status until the cube is done refreshing
    while 'Processing' in cube.show_status():
        time.sleep(10)
        cube.refresh_status()
    toc = time.perf_counter()
    status = f'Finished refreshing {cube.name} in {get_time_elapsed(tic, toc)}'
    return status

But if the refresh fails, it doesnt detect it, it's only checking if the refresh is still happening. I'm not seeing any obvious methods in the Job or OlapCube objects to determine if a refresh failed. Ideally I can detect when it fails and display the reason for failure, the same error message I see in Workstation>Monitors>Jobs tab. Thanks

rickymedrano commented 3 months ago

I've also tried getting job.status but it always returns JobStatus.EXECUTING, way after the job already completed. So I try using job.fetch() to see if it will update the JobStatus but the method immediately errors out saying the Job is not found once the job finishes.

apiotrowskiMicroStrategy commented 1 month ago

Hi @rickymedrano

We will provide the code snippet required to do exactly that with next release.