<commit_before>#coding: utf-8
from flask import current_app
from flask.ext.restplus import marshal
from ..models.hail import Hail
from ..models.security import User
from ..descriptors.hail import hail_model
from ..extensions import db, celery
import requests, json

@celery.task()
def send_request_operator(hail_id, operateur_id, env):
    hail = Hail.query.get(hail_id)
    if not hail:
        current_app.logger.error('Unable to find hail: {}'.format(hail_id))
        return False
    operateur = User.query.get(operateur_id)
    if not operateur:
        current_app.logger.error('Unable to find operateur: {}'.format(operateur_id))
        return False

    r = None
    endpoint = operateur.hail_endpoint(env)
    try:
        headers = {'Content-Type': 'application/json',
                   'Accept': 'application/json'}
        if operateur.operator_header_name is not None and operateur.operator_header_name != '':
            headers[operateur.operator_header_name] = operateur.operator_api_key
        r = requests.post(endpoint, data=json.dumps(marshal({"data": [hail]}, hail_model)),
            headers=headers)
    except requests.exceptions.MissingSchema:
        pass
    if not r or r.status_code < 200 or r.status_code >= 300:
        hail.status = 'failure'
        db.session.commit()
        current_app.logger.error("Unable to reach hail's endpoint {} of operator {}"\
            .format(endpoint, operateur.email))<commit_msg>Use cache in celery task<commit_after>#coding: utf-8
from flask import current_app
from flask.ext.restplus import marshal
from ..models.hail import Hail
from ..models.security import User
from ..descriptors.hail import hail_model
from ..extensions import db, celery
import requests, json

@celery.task()
def send_request_operator(hail_id, operateur_id, env):
    hail = Hail.cache.get(hail_id)
    if not hail:
        current_app.logger.error('Unable to find hail: {}'.format(hail_id))
        return False
    operateur = User.query.get(operateur_id)
    if not operateur:
        current_app.logger.error('Unable to find operateur: {}'.format(operateur_id))
        return False

    r = None
    endpoint = operateur.hail_endpoint(env)
    try:
        headers = {'Content-Type': 'application/json',
                   'Accept': 'application/json'}
        if operateur.operator_header_name is not None and operateur.operator_header_name != '':
            headers[operateur.operator_header_name] = operateur.operator_api_key
        r = requests.post(endpoint, data=json.dumps(marshal({"data": [hail]}, hail_model)),
            headers=headers)
    except requests.exceptions.MissingSchema:
        pass
    if not r or r.status_code < 200 or r.status_code >= 300:
        hail.status = 'failure'
        db.session.commit()
        current_app.logger.error("Unable to reach hail's endpoint {} of operator {}"\
            .format(endpoint, operateur.email))
{'fraction_non_alphanumeric': 0.10695920466232431, 'fraction_numerical': 0.0047994514912581415, 'mean_word_length': 3.150782361308677, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '4996153', 'n_tokens_mistral': 894, 'n_tokens_neox': 856, 'n_words': 219}