Sha256: 0bb8b4e2c4e6cc11311cf376f047c649e1daed1984d4e4379ac5fcf0eaadef72

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

module Aeternitas
  module WebUi
    class PollablesController < Aeternitas::WebUi::ApplicationController
      include ActionController::ImplicitRender

      before_action :set_pollable, except: [:index]
      before_action :set_timerange, only: [:timeline, :execution_time, :data_growth]

      def index
        @pollable_classes = Aeternitas::PollableMetaData
          .distinct(:pollable_class)
          .pluck(:pollable_class)
          .map(&:constantize)
      end

      def show ; end

      def timeline ; end

      def execution_time
        @polling_time = Aeternitas::Metrics.execution_time(@pollable, from: @from, to: @to, resolution: @resolution)
      end

      def data_growth
        @pollables_created = Aeternitas::Metrics.pollables_created(@pollable, from: @from, to: @to, resolution: @resolution)
        @sources_created = Aeternitas::Metrics.sources_created(@pollable, from: @from, to: @to, resolution: @resolution)
      end

      def deactivated_pollables
        start = params.fetch(:start, 0)
        limit = params.fetch(:length, 10)

        @pollable_meta_data = Aeternitas::PollableMetaData
          .deactivated
          .includes(:pollable)
          .where(pollable_class: @pollable.name)
          .limit(limit)
          .offset(start)
          .order(deactivated_at: :desc)
      end

      def all_pollables
        start = params.fetch(:start, 0)
        limit = params.fetch(:length, 10)

        @pollable_meta_data = Aeternitas::PollableMetaData
          .where(pollable_class: @pollable.name)
          .includes(pollable: :sources)
          .limit(limit)
          .offset(start)
          .order(last_polling: :desc)
      end

      private

      def set_pollable
        pollable_name = params.fetch(:id)

        if Aeternitas::PollableMetaData.where(pollable_class: pollable_name).exists?
          @pollable = pollable_name.constantize
        else
          render_error(404, "Pollable of type #{pollable_name} not found")
          false
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aeternitas_web_ui-0.2.1 app/controllers/aeternitas/web_ui/pollables_controller.rb
aeternitas_web_ui-0.2.0 app/controllers/aeternitas/web_ui/pollables_controller.rb