Move worker methods into Worker class and expose more TaskSpec fields to Python. (#796)

* Move worker methods inside worker class. Move some helper methods from actor.py into utils.py and state.py.

* Add more methods exposing task spec fields to Python.

* Fix linting.

* Fix error.

* Remove unused code in default worker.
This commit is contained in:
Robert Nishihara
2017-08-01 17:16:57 -07:00
committed by Philipp Moritz
parent 52a27be364
commit 8c8258de20
8 changed files with 520 additions and 402 deletions
+21
View File
@@ -347,6 +347,11 @@ static PyObject *PyTask_actor_id(PyObject *self) {
return PyObjectID_make(actor_id);
}
static PyObject *PyTask_actor_counter(PyObject *self) {
int64_t actor_counter = TaskSpec_actor_counter(((PyTask *) self)->spec);
return PyLong_FromLongLong(actor_counter);
}
static PyObject *PyTask_driver_id(PyObject *self) {
UniqueID driver_id = TaskSpec_driver_id(((PyTask *) self)->spec);
return PyObjectID_make(driver_id);
@@ -357,6 +362,16 @@ static PyObject *PyTask_task_id(PyObject *self) {
return PyObjectID_make(task_id);
}
static PyObject *PyTask_parent_task_id(PyObject *self) {
TaskID task_id = TaskSpec_parent_task_id(((PyTask *) self)->spec);
return PyObjectID_make(task_id);
}
static PyObject *PyTask_parent_counter(PyObject *self) {
int64_t parent_counter = TaskSpec_parent_counter(((PyTask *) self)->spec);
return PyLong_FromLongLong(parent_counter);
}
static PyObject *PyTask_arguments(PyObject *self) {
TaskSpec *task = ((PyTask *) self)->spec;
int64_t num_args = TaskSpec_num_args(task);
@@ -404,8 +419,14 @@ static PyObject *PyTask_returns(PyObject *self) {
static PyMethodDef PyTask_methods[] = {
{"function_id", (PyCFunction) PyTask_function_id, METH_NOARGS,
"Return the function ID for this task."},
{"parent_task_id", (PyCFunction) PyTask_parent_task_id, METH_NOARGS,
"Return the task ID of the parent task."},
{"parent_counter", (PyCFunction) PyTask_parent_counter, METH_NOARGS,
"Return the parent counter of this task."},
{"actor_id", (PyCFunction) PyTask_actor_id, METH_NOARGS,
"Return the actor ID for this task."},
{"actor_counter", (PyCFunction) PyTask_actor_counter, METH_NOARGS,
"Return the actor counter for this task."},
{"driver_id", (PyCFunction) PyTask_driver_id, METH_NOARGS,
"Return the driver ID for this task."},
{"task_id", (PyCFunction) PyTask_task_id, METH_NOARGS,