def poll(self):
        """Check for a task state like `docker service ps id`"""
        service = yield self.get_service()
        if not service:
            self.log.warn("Docker service not found")
            return 0

        task_filter = {'service': service['Spec']['Name']}

        tasks = yield self.docker(
            'tasks', task_filter
        )

        running_task = None
        for task in tasks:
            task_state = task['Status']['State']
            self.log.debug(
                "Task %s of Docker service %s status: %s",
                task['ID'][:7],
                self.service_id[:7],
                pformat(task_state),
            )
            if task_state == 'running':
                # there should be at most one running task
                running_task = task

        if running_task is not None:
            return None
        else:
            return 1
Check for a task state like `docker service ps id`