<commit_before>import newrelic.agent
from celery import task

from treeherder.etl.classification_mirroring import ElasticsearchDocRequest


@task(name="submit-elasticsearch-doc", max_retries=10, time_limit=30)
def submit_elasticsearch_doc(project, job_id, bug_id, classification_timestamp, who):
    """
    Mirror the classification to Elasticsearch using a post request, until
    OrangeFactor is rewritten to use Treeherder's API directly.
    """
    newrelic.agent.add_custom_parameter("project", project)
    newrelic.agent.add_custom_parameter("job_id", job_id)
    newrelic.agent.add_custom_parameter("bug_id", bug_id)
    try:
        req = ElasticsearchDocRequest(project, job_id, bug_id, classification_timestamp, who)
        req.generate_request_body()
        req.send_request()
    except Exception as e:
        # Initially retry after 1 minute, then for each subsequent retry
        # lengthen the retry time by another minute.
        submit_elasticsearch_doc.retry(exc=e, countdown=(1 + submit_elasticsearch_doc.request.retries) * 60)
        # this exception will be raised once the number of retries
        # exceeds max_retries
        raise<commit_msg>Bug 1284289 - Use @retryable_task with the submit_elasticsearch_doc task<commit_after>import newrelic.agent

from treeherder.etl.classification_mirroring import ElasticsearchDocRequest
from treeherder.workers.task import retryable_task


@retryable_task(name="submit-elasticsearch-doc", max_retries=10, time_limit=30)
def submit_elasticsearch_doc(project, job_id, bug_id, classification_timestamp, who):
    """
    Mirror the classification to Elasticsearch using a post request, until
    OrangeFactor is rewritten to use Treeherder's API directly.
    """
    newrelic.agent.add_custom_parameter("project", project)
    newrelic.agent.add_custom_parameter("job_id", job_id)
    newrelic.agent.add_custom_parameter("bug_id", bug_id)
    req = ElasticsearchDocRequest(project, job_id, bug_id, classification_timestamp, who)
    req.generate_request_body()
    req.send_request()
{'fraction_non_alphanumeric': 0.07782101167315175, 'fraction_numerical': 0.00924124513618677, 'mean_word_length': 4.893982808022923, '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': '5827492', 'n_tokens_mistral': 611, 'n_tokens_neox': 601, 'n_words': 147}