<commit_before>########
# Copyright (c) 2014 GigaSpaces Technologies Ltd. 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.

__author__ = 'dank'

import time
import uuid

from cloudify.celery import celery as celery_client


TASK_PENDING = 'pending'
TASK_SENDING = 'sending'
TASK_SENT = 'sent'
TASK_STARTED = 'started'
TASK_SUCCEEDED = 'succeeded'
TASK_FAILED = 'failed'


HANDLER_RETRY = 'handler_retry'
HANDLER_FAIL = 'handler_fail'
HANDLER_IGNORE = 'handler_ignore'
HANDLER_CONTINUE = 'handler_continue'


def retry_failure_handler(task):
    return HANDLER_RETRY


class WorkflowTask(object):
    """A base class for workflow tasks"""

    def __init__(self,
                 task_id=None,
                 info=None,
                 on_success=None,
                 on_failure=None):
        """
        :param task_id: The id of this task (generated if none is provided)
        :param info: A short description of this task (for logging)
        :param on_success: A handler called when the task's execution
                           terminates successfully.
                           Expected to return a bool, where True signifies
                           the task should be retried, and False signifies
                           no additional action for this task should be taken
        :param on_failure: A handler called when the task's execution
                           fails.
                           Expected to return a bool, where True signifies
                           the error was handled and should be ignored by
                           the workflow engine, and False signifies the
                           workflow should end immediately with a failure.
        """
        self.id = task_id or str(uuid.uuid4())
        self._state = TASK_PENDING
        self.async_result = None
        self.on_success = on_success
        self.on_failure = on_failure
        self.info = info
        self.error = None
        self.total_retries = 1
        self.current_retries = 0
        # timestamp for which the task should not be executed
        # by the task graph before reached, overridden by the task
        # graph during retries
        self.execute_after = time.time()

    def is_remote(self):
        """
        :return: Is this a remote task
        """
        return not self.is_local()

    def get_state(self):
        """
        Get the task state

        :return: The task state [pending, sending, sent, started, succeeded,
                                 failed]
        """
        return self._state

    def set_state(self, state):<commit_msg>CFY-799 update docs<commit_after>########
# Copyright (c) 2014 GigaSpaces Technologies Ltd. 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.

__author__ = 'dank'

import time
import uuid

from cloudify.celery import celery as celery_client


TASK_PENDING = 'pending'
TASK_SENDING = 'sending'
TASK_SENT = 'sent'
TASK_STARTED = 'started'
TASK_SUCCEEDED = 'succeeded'
TASK_FAILED = 'failed'


HANDLER_RETRY = 'handler_retry'
HANDLER_FAIL = 'handler_fail'
HANDLER_IGNORE = 'handler_ignore'
HANDLER_CONTINUE = 'handler_continue'


def retry_failure_handler(task):
    """Basic on_success/on_failure handler that always returns retry"""
    return HANDLER_RETRY


class WorkflowTask(object):
    """A base class for workflow tasks"""

    def __init__(self,
                 task_id=None,
                 info=None,
                 on_success=None,
                 on_failure=None):
        """
        :param task_id: The id of this task (generated if none is provided)
        :param info: A short description of this task (for logging)
        :param on_success: A handler called when the task's execution
                           terminates successfully.
                           Expected to return one of
                           [handler_retry, handler_continue] to indicate
                           whether this task should be re-executed.
        :param on_failure: A handler called when the task's execution
                           fails.
                           Expected to return one of
                           [handler_retry, handler_fail, handler_ignore]
                           to indicate whether this task should be re-executed,
                           cause the engine to terminate workflow execution
                           immediately or simply ignore this task failure and
                           move on.
        """
        self.id = task_id or str(uuid.uuid4())
        self._state = TASK_PENDING
        self.async_result = None
        self.on_success = on_success
        self.on_failure = on_failure
        self.info = info
        self.error = None
        self.total_retries = 1
        self.current_retries = 0
        # timestamp for which the task should not be executed
        # by the task graph before reached, overridden by the task
        # graph during retries
        self.execute_after = time.time()

    def is_remote(self):
        """
        :return: Is this a remote task
        """
        return not self.is_local()

    def get_state(self):
        """
        Get the task state

        :return: The task state [pending, sending, sent, started, succeeded,
                                 failed]
        """
        return self._state

    def set_state(self, state):
{'fraction_non_alphanumeric': 0.06680161943319839, 'fraction_numerical': 0.003892868265337901, 'mean_word_length': 2.071736011477762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7629892', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1651, 'n_words': 626}