# Path: botoflow/core/exceptions.py
# class CancellationError(Exception):
#     """
#     Cancellation error exception
#     """
#     pass
# 
# Path: botoflow/context/context_base.py
# class ContextBase(object):
# 
#     thread_local = threading.local()
# 
#     # Python has no good support for class properties
#     @classmethod
#     def get_context(cls):
#         context = cls.thread_local.flow_current_context
#         if DEBUG:
#             log.debug("Current context: %s", context)
#         return context
# 
#     @classmethod
#     def set_context(cls, context):
#         if DEBUG:
#             log.debug("Setting context: %s", context)
#         cls.thread_local.flow_current_context = context


from botoflow.core.exceptions import CancellationError
from .context_base import ContextBase
    :py:func:`botoflow.get_context` and provides the ability to
    retrieve information about the workflow as well as access to the
    :py:meth:`heartbeat` for heartbeating the execution of activity
    """

    def __init__(self, worker, task):
        """

        :param worker:
        :type worker: botoflow.workers.activity_worker.ActivityWorker
        :param task:
        :type task: botoflow.workers.activity_task.ActivityTask
        """

        self.worker = worker
        self.task = task

    def heartbeat(self, details=None):
        """Heartbeats current activity, raising CancellationError if cancel requested.

        Ignore request by catching the exception, or let it raise to cancel.

        :param details: If specified, contains details about the progress of the task.
        :type details: str
        :raises CancellationError: if uncaught, will record this activity as cancelled
            in SWF history, and bubble up to the decider, where it will cancel the
            workflow.
        """
        result = self.worker.request_heartbeat(self.task, details)
        if result['cancelRequested']:

# Path: botoflow/core/exceptions.py
# class CancellationError(Exception):
#     """
#     Cancellation error exception
#     """
#     pass
# 
# Path: botoflow/context/context_base.py
# class ContextBase(object):
# 
#     thread_local = threading.local()
# 
#     # Python has no good support for class properties
#     @classmethod
#     def get_context(cls):
#         context = cls.thread_local.flow_current_context
#         if DEBUG:
#             log.debug("Current context: %s", context)
#         return context
# 
#     @classmethod
#     def set_context(cls, context):
#         if DEBUG:
#             log.debug("Setting context: %s", context)
#         cls.thread_local.flow_current_context = context


# Path: botoflow/context/activity_context.py
from botoflow.core.exceptions import CancellationError
from .context_base import ContextBase

    :py:func:`botoflow.get_context` and provides the ability to
    retrieve information about the workflow as well as access to the
    :py:meth:`heartbeat` for heartbeating the execution of activity
    """

    def __init__(self, worker, task):
        """

        :param worker:
        :type worker: botoflow.workers.activity_worker.ActivityWorker
        :param task:
        :type task: botoflow.workers.activity_task.ActivityTask
        """

        self.worker = worker
        self.task = task

    def heartbeat(self, details=None):
        """Heartbeats current activity, raising CancellationError if cancel requested.

        Ignore request by catching the exception, or let it raise to cancel.

        :param details: If specified, contains details about the progress of the task.
        :type details: str
        :raises CancellationError: if uncaught, will record this activity as cancelled
            in SWF history, and bubble up to the decider, where it will cancel the
            workflow.
        """
        result = self.worker.request_heartbeat(self.task, details)
        if result['cancelRequested']:

            raise CancellationError('Cancel was requested during activity heartbeat')