<commit_before># Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

import datetime
import Queue

from kombu import Connection
from oslo.config import cfg

from st2actions.container.base import RunnerContainer
from st2common import log as logging
from st2common.models.db.execution import ActionExecutionDB
from st2common.persistence.execution import ActionExecution
from st2common.transport import consumers, execution, publishers
from st2common.util import isotime


LOG = logging.getLogger(__name__)

EXPORTER_WORK_Q = execution.get_queue(
    'st2.exporter.work', routing_key=publishers.UPDATE_RK)


class ExecutionsExporter(consumers.MessageHandler):
    message_type = ActionExecutionDB

    def __init__(self, connection, queues):
        super(ExecutionsExporter, self).__init__(connection, queues)
        self.container = RunnerContainer()
        self.persisted_timestamp = None
        self.pending_executions = Queue.Queue()

    def start(self, wait=False):
        self._bootstrap()
        super(ExecutionsExporter, self).start(wait=wait)

    def shutdown(self):
        super(ExecutionsExporter, self).shutdown()

    def process(self, execution):
        pass

    def _bootstrap(self):
        marker = self._get_export_marker_from_db()
        missed_executions = self._get_missed_executions_from_db(export_marker=marker)

        for missed_execution in missed_executions:
            try:
                self.pending_executions.put_nowait(missed_execution)
            except:
                LOG.exception('Failed adding execution to in-memory queue.')<commit_msg>Convert execution db model to API model before putting it in queueue<commit_after># Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

import datetime
import Queue

from kombu import Connection
from oslo.config import cfg

from st2common import log as logging
from st2common.models.api.execution import ActionExecutionAPI
from st2common.models.db.execution import ActionExecutionDB
from st2common.persistence.execution import ActionExecution
from st2common.transport import consumers, execution, publishers
from st2common.util import isotime
from st2common.util.jsonify import json_encode

LOG = logging.getLogger(__name__)

EXPORTER_WORK_Q = execution.get_queue(
    'st2.exporter.work', routing_key=publishers.UPDATE_RK)


class ExecutionsExporter(consumers.MessageHandler):
    message_type = ActionExecutionDB

    def __init__(self, connection, queues):
        super(ExecutionsExporter, self).__init__(connection, queues)
        self.persisted_timestamp = None
        self.pending_executions = Queue.Queue()

    def start(self, wait=False):
        self._bootstrap()
        super(ExecutionsExporter, self).start(wait=wait)

    def shutdown(self):
        super(ExecutionsExporter, self).shutdown()

    def process(self, execution):
        execution_api = ActionExecutionAPI.from_model(execution)
        execution_json = json_encode(execution_api)
        self.pending_executions.put_nowait(execution_json)

    def _bootstrap(self):
        marker = self._get_export_marker_from_db()
        missed_executions = self._get_missed_executions_from_db(export_marker=marker)

        for missed_execution in missed_executions:
            execution_json = json_encode(ActionExecutionAPI.from_model(execution))
            try:
                self.pending_executions.put_nowait(execution_json)
            except:
                LOG.exception('Failed adding execution to in-memory queue.')
{'fraction_non_alphanumeric': 0.06677458518818292, 'fraction_numerical': 0.0046539862403885066, 'mean_word_length': 4.059365404298874, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1863455', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1275, 'n_words': 434}