def __init__(self, opts):
        super(FeedComponent, self).__init__(opts)

        try:
            self.options = opts.get("feeds", {})
            LOG.debug(self.options)

            self.channel = "actions." + self.options.get("queue", "feed_data")

            if self.options.get("feed_names") is None:
                LOG.error("No feed_names are specified")
            else:
                rest_client_helper = RestClientHelper(self.rest_client)

                self.feed_outputs = build_feed_outputs(
                    rest_client_helper, opts,
                    self.options.get("feed_names", None))

                # determine the reload options to follow
                if self.options.get('reload', 'false').lower() == 'true':
                    query_api_method = str_to_bool(
                        self.options.get("reload_query_api_method", 'false'))

                    reload = Reload(rest_client_helper,
                                    self.feed_outputs,
                                    query_api_method=query_api_method)
                    reload.reload_all()

        except Exception as err:
            LOG.error("exception: %s", err)
            error_trace = traceback.format_exc()
            LOG.error("Traceback %s", error_trace)
    def _feed_ingest_data(self, event, *args, **kwargs):  # pylint: disable=unused-argument
        """Ingests data of any type that can be sent to a Resilient message destination"""
        if not isinstance(event, ActionMessage):
            # Some event we are not interested in
            return

        try:
            log = logging.getLogger(__name__)
            log.info("ingesting object")
            rest_client_helper = RestClientHelper(self.rest_client)

            type_info = ActionMessageTypeInfo(
                event.message['object_type'], event.message['type_info'],
                rest_client_helper.inst_rest_client)

            type_name = type_info.get_pretty_type_name()

            inc_id = _get_inc_id(event.message)

            is_deleted = event.message['operation_type'] == 'deleted'

            if type_info.is_data_table():
                payload = event.message['row']
            else:
                payload = event.message[type_name]

            send_data(type_info, inc_id, rest_client_helper, payload,
                      self.feed_outputs, is_deleted)

        except Exception as err:
            LOG.error(err)
            LOG.error("Failure on action %s object %s type_info %s",
                      event.message['operation_type'],
                      event.message['object_type'], event.message['type_info'])
    def _data_feeder_sync_incidents_function(self, event, *args, **kwargs):
        """Function: Synchronize Incident(s) and their associated tasks, notes, attachments, artifacts, milestones and associated datatables"""
        try:
            # Get the wf_instance_id of the workflow this Function was called in
            wf_instance_id = event.message["workflow_instance"][
                "workflow_instance_id"]

            result = ResultPayload("data_feeder", **kwargs)

            # Get the function parameters:
            df_min_incident_id = kwargs.get("df_min_incident_id")  # number
            df_max_incident_id = kwargs.get("df_max_incident_id",
                                            df_min_incident_id)  # number
            df_query_api_method = kwargs.get("df_query_api_method",
                                             False)  # boolean

            log = logging.getLogger(__name__)
            log.info("df_min_incident_id: %s", df_min_incident_id)
            log.info("df_max_incident_id: %s", df_max_incident_id)

            if not df_max_incident_id:
                df_max_incident_id = df_min_incident_id

            if df_min_incident_id > df_max_incident_id:
                raise ValueError(
                    "Min value {} greater than max value {}".format(
                        df_min_incident_id, df_max_incident_id))

            # select all incidents as max
            if df_max_incident_id == 0:
                df_max_incident_id = sys.maxsize

            yield StatusMessage("starting...")
            rest_client_helper = RestClientHelper(self.rest_client)
            feed_outputs = build_feed_outputs(
                rest_client_helper, self.opts,
                self.options.get("feed_names", None))

            # expose attachment content setting
            self.incl_attachment_data = str_to_bool(
                self.options.get("include_attachment_data", 'false'))

            df = Reload(rest_client_helper,
                        feed_outputs,
                        query_api_method=df_query_api_method,
                        incl_attachment_data=self.incl_attachment_data)
            reloaded_incidents = df.reload_all(min_inc_id=df_min_incident_id,
                                               max_inc_id=df_max_incident_id)

            result_payload = result.done(
                True, {"num_of_sync_incidents": reloaded_incidents})

            yield StatusMessage("done...")

            # Produce a FunctionResult with the results
            yield FunctionResult(result_payload)
        except Exception:
            yield FunctionError()