abraham-ai / eden

Eden converts your python function into a hosted endpoint with minimal changes to your existing code :mage_man:
GNU General Public License v3.0
47 stars 5 forks source link

progress callbacks in in run #5

Closed Mayukhdeb closed 3 years ago

Mayukhdeb commented 3 years ago

There should be a way for the client to know how far the task is complete while it's running.

Instead of:

{'status': 'running'}

it could be returnning a progress value where 0 = just started and 1. = complete.

{'status': 'running', 'progress' : '0.3'}

and this can be integrated into run() function as:

@eden_block.run(args = my_args, progress = True)
def do_something(config): 
    # other stuff

    for i in range(100):
        config['__progress__'].update(0.01)

and the ajax jquery might look like:

if (status == 'completed') {
    $('#status').html('');
        refresh_creations();
} 

else if (status == 'running'){
    var status_str = 'Task '+task_id+' is running. Progress: ' + request.getResponseHeader('progress');
    $('#status').html(status_str);
    setTimeout(function() {
    check_status();
}, 5000);
Mayukhdeb commented 3 years ago

Progress gets tracked with ProgressTracker. It can be used within the block as https://github.com/abraham-ai/eden/blob/26cedda3bbf1507fea3a42a5cf4aa66366d96ab5/server_example.py#L21-L22