| 25 | from mesos.executor import MesosExecutorDriver |
| 26 | |
| 27 | class MyExecutor(mesos.interface.Executor): |
| 28 | def launchTask(self, driver, task): |
| 29 | # Create a thread to run the task. Tasks should always be run in new |
| 30 | # threads or processes, rather than inside launchTask itself. |
| 31 | def run_task(): |
| 32 | print "Running task %s" % task.task_id.value |
| 33 | update = mesos_pb2.TaskStatus() |
| 34 | update.task_id.value = task.task_id.value |
| 35 | update.state = mesos_pb2.TASK_RUNNING |
| 36 | update.data = 'data with a \0 byte' |
| 37 | driver.sendStatusUpdate(update) |
| 38 | |
| 39 | # This is where one would perform the requested task. |
| 40 | |
| 41 | print "Sending status update..." |
| 42 | update = mesos_pb2.TaskStatus() |
| 43 | update.task_id.value = task.task_id.value |
| 44 | update.state = mesos_pb2.TASK_FINISHED |
| 45 | update.data = 'data with a \0 byte' |
| 46 | driver.sendStatusUpdate(update) |
| 47 | print "Sent status update" |
| 48 | |
| 49 | thread = threading.Thread(target=run_task) |
| 50 | thread.start() |
| 51 | |
| 52 | def frameworkMessage(self, driver, message): |
| 53 | # Send it back to the scheduler. |
| 54 | driver.sendFrameworkMessage(message) |
| 55 | |
| 56 | if __name__ == "__main__": |
| 57 | print "Starting executor" |