Sha256: 33eeef7e48b31a90bdb5bb03f43c7fee2cf81a7c3a7189b47e72fd046327fe5c

Contents?: true

Size: 956 Bytes

Versions: 1

Compression:

Stored size: 956 Bytes

Contents

# frozen_string_literal: true

require 'action_view'
require 'action_view/helpers'
require 'sidekiq/cli'
require 'sidekiqtui/version'
require 'tty-box'
require 'tty-screen'
require 'tty-table'

include ActionView::Helpers::DateHelper

module Sidekiqtui
  module_function

  def run
    configure

    box = TTY::Box.frame(
      width: TTY::Screen.width,
      height: TTY::Screen.height,
      title: { top_left: 'Scheduled Jobs', bottom_right: Sidekiqtui::VERSION }
    ) do
      ss = Sidekiq::ScheduledSet.new
      jobs = ss.map do |job|
        [
          "in #{time_ago_in_words(job.at)}",
          job.queue,
          job.item['class'],
          job.args.join(', ')
        ]
      end.reverse

      table = TTY::Table.new(
        %w[When Queue Job Arguments],
        jobs
      )
      table.render(:unicode)
    end

    print box
  end

  def configure
    Sidekiq.configure_server do |config|
      config.logger = nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiqtui-0.1.2 lib/sidekiqtui.rb