<commit_before>"""Solvebio Task API Resource"""
from .apiresource import ListableAPIResource


class Task(ListableAPIResource):
    """
    Tasks are operations on datasets or vaults.
    """
    RESOURCE_VERSION = 2

    LIST_FIELDS = (
        ('id', 'ID'),
        ('task_display_name', 'Task Type'),
        ('task_id', 'Task ID'),
        ('description', 'Description'),
        ('status', 'Status'),
        ('created_at', 'Created'),
    )

    @property
    def child_object(self):
        """ Get Task child object class """
        from . import types
        child_klass = types.get(self.task_type.split('.')[1])
        return child_klass.retrieve(self.task_id, client=self._client)

    def follow(self):
        """ Follow the child object but do not loop """
        self.child_object.follow(loop=False)<commit_msg>add shortcut to cancel tasks<commit_after>"""Solvebio Task API Resource"""
from .apiresource import ListableAPIResource


class Task(ListableAPIResource):
    """
    Tasks are operations on datasets or vaults.
    """
    RESOURCE_VERSION = 2

    LIST_FIELDS = (
        ('id', 'ID'),
        ('task_display_name', 'Task Type'),
        ('task_id', 'Task ID'),
        ('description', 'Description'),
        ('status', 'Status'),
        ('created_at', 'Created'),
    )

    @property
    def child_object(self):
        """ Get Task child object class """
        from . import types
        child_klass = types.get(self.task_type.split('.')[1])
        return child_klass.retrieve(self.task_id, client=self._client)

    def follow(self):
        """ Follow the child object but do not loop """
        self.child_object.follow(loop=False)

    def cancel(self):
        """ Cancel a task """
        if 'cancel' not in self.available_actions:
            # It may not be queued/running or another
            # possible reason.
            print("Task can not be canceled.")
            return

        child_ = self.child_object
        child_.status = 'canceled'
        child_.save()
{'fraction_non_alphanumeric': 0.1309935739001483, 'fraction_numerical': 0.001977261492832427, 'mean_word_length': 2.4657534246575343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5738217', 'n_tokens_mistral': 584, 'n_tokens_neox': 567, 'n_words': 155}