Files
deb-python-taskflow/taskflow/promise.py

50 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import abc
class Promise(object):
"""This is an abstraction of a promise to perform some type of job which
can be returned to a user/function... for later lookup on the progress of
the underlying job."""
__metaclass__ = abc.ABCMeta
def __init__(self, job):
self._job = job
@property
def tracking_id(self):
return "p-%s" % (self._job.tracking_id)
def await(self, timeout=None):
"""Attempts to wait until the job fails or finishess."""
raise NotImplementedError()
@abc.abstractproperty
def state(self):
"""Returns the state of the underlying job."""
raise NotImplementedError()
@abc.abstractproperty
def owner(self):
"""Returns the owner of the job, or None if no owner
has been assigned."""
raise NotImplementedError()