<commit_before>#!/usr/bin/env python

import datetime
import time
from urlparse import urlparse

import requests

from requests.exceptions import RequestException

# Needs to be run in a Stackstorm virtualenv
from st2actions.runners.pythonrunner import Action




class PollStatus(Action):
    """
    Polls a give micro service URL for current status of some long running process.

    Will check the HTTP server's response to determine whether or not the process has finished
    processing. It expects a JSON field called "state", and will continue to poll the URL
    as long as "state" equals "started". If e.g. "done", "error", or "none" is received an
    error is generated and the polling stops.
    """

    def query(self, url, verify_ssl_cert):
        try:
            resp = requests.get(url, verify=verify_ssl_cert)
            return resp
        except RequestException as err:
            self.logger.error("An error was encountered when "
                              "querying url: {0},  {1}".format(url, err))
            raise err

    def post_to_endpoint(self, endpoint, body, irma_mode, verify_ssl_cert):

        def _rewrite_link(link):
            endpoint_parsed = urlparse(endpoint)
            # Gets the first non-empty element from the path, this lets it account
            # for multiple slashes
            first_part_of_path = filter(None, endpoint_parsed.path.split('/'))[0]
            link_parsed = urlparse(link)
            return "{}://{}/{}{}?{}".format(endpoint_parsed.scheme,
                                            endpoint_parsed.netloc,
                                            first_part_of_path,
                                            link_parsed.path,
                                            endpoint_parsed.query)

        try:
            response = requests.post(endpoint, json=body, verify=verify_ssl_cert)
            response_json = response.json()

            if irma_mode:
                modified_link = _rewrite_link(response_json['link'])
                self.logger.info("In irma mode, will rewrite link to: {}".format(modified_link))
                return modified_link<commit_msg>We want to see which versions the services are running<commit_after>#!/usr/bin/env python

import datetime
import time
from urlparse import urlparse

import requests

from requests.exceptions import RequestException

# Needs to be run in a Stackstorm virtualenv
from st2actions.runners.pythonrunner import Action

class PollStatus(Action):
    """
    Polls a give micro service URL for current status of some long running process.

    Will check the HTTP server's response to determine whether or not the process has finished
    processing. It expects a JSON field called "state", and will continue to poll the URL
    as long as "state" equals "started". If e.g. "done", "error", or "none" is received an
    error is generated and the polling stops.
    """

    def query(self, url, verify_ssl_cert):
        try:
            resp = requests.get(url, verify=verify_ssl_cert)
            return resp
        except RequestException as err:
            self.logger.error("An error was encountered when "
                              "querying url: {0},  {1}".format(url, err))
            raise err

    def post_to_endpoint(self, endpoint, body, irma_mode, verify_ssl_cert):

        def _rewrite_link(link):
            endpoint_parsed = urlparse(endpoint)
            # Gets the first non-empty element from the path, this lets it account
            # for multiple slashes
            first_part_of_path = filter(None, endpoint_parsed.path.split('/'))[0]
            link_parsed = urlparse(link)
            return "{}://{}/{}{}?{}".format(endpoint_parsed.scheme,
                                            endpoint_parsed.netloc,
                                            first_part_of_path,
                                            link_parsed.path,
                                            endpoint_parsed.query)

        try:
            response = requests.post(endpoint, json=body, verify=verify_ssl_cert)
            response_json = response.json()
            self.logger.info("Service accepted our request and responded with payload: {}".format(response_json))

            if irma_mode:
                modified_link = _rewrite_link(response_json['link'])
                self.logger.info("In irma mode, will rewrite link to: {}".format(modified_link))
                return modified_link
{'fraction_non_alphanumeric': 0.07809013833110219, 'fraction_numerical': 0.00178491744756805, 'mean_word_length': 2.0600682593856656, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1839128', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1100, 'n_words': 375}