[Kimchi-devel] [Wok] [RFC] Issue #122: Make AsyncTask stoppable.

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Mon Jun 6 14:21:54 UTC 2016


This is an RFC for "Make AsyncTask stoppable" in Wok (and any other plugin). The
main idea is give to user a way to stop a Task that is still running, cleaning
all references and processes and setting the Task status to "killed".

To do this, the Task API need to be modified, by implementing the DELETE method
in Task Resource. Said that, the API will look like:

### Resource: Task

**URI:** /tasks/*:id*

A task represents an asynchronous operation that is being performed by the
server.

**Methods:**

* **GET**: Retrieve the full description of the Task
    * id: The Task ID is used to identify this Task in the API.
    * status: The current status of the Task
        * running: The task is running
        * finished: The task has finished successfully
        * failed: The task failed
+        * killed: The task was killed by user
    * message: Human-readable details about the Task status
    * target_uri: Resource URI related to the Task
+* **DELETE**: Delete the Task
* **POST**: *See Task Actions*

**Actions (POST):**

*No actions defined*

Since an AsyncTask is basic a thread running in the system and this thread can
execute a pure Python method or a background command (by using run_command()
from wok.utils), the developer must pass as argument to the add_task() a method
to be executed by the DELETE operation, called here as 'kill_cb'. With this
idea, the add_task() method and also the AsyncTask constructor will be like:

def add_task(target_uri, fn, objstore, kill_cb=None, opaque=None):

class AsyncTask(object):
    def __init__(self, id, target_uri, fn, objstore, kill_cb=None, opaque=None):

If none kill_cb is passed, the task will not be able to stopped and an error (or
warning) message will be raised to user if DELETE operation is executed.
Otherwise, the kill_cb method will be executed by kill() method (responsible to
execute the DELETE operation) of AsyncTask class and its status set to 'killed'.

If you have any comments or suggestions, please feel free to reply to ML.

Thanks and bestr regards,
--
Paulo Ricardo Paz Vital
Linux Technology Center, IBM Systems
http://www.ibm.com/linux/ltc/




More information about the Kimchi-devel mailing list