Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mensfeld committed Sep 1, 2024
1 parent d5cb5ef commit 9d28ea9
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def index
def show(schedule_name)
@schedule_name = schedule_name
@stats_topic_name = "#{schedule_name}#{states_postfix}"
@stats_info = Karafka::Admin.topic_info(@stats_topic_name)

@states = {}
@stats_info[:partition_count].times { |i| @states[i] = false }

Karafka::Pro::Iterator.new({ @stats_topic_name => -1 }).each do |message|
@states[message.partition] = message.payload
Expand Down
61 changes: 36 additions & 25 deletions lib/karafka/web/pro/ui/views/scheduled_messages/schedules/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,44 @@
Partition <%= partition %>
</h3>

<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>Date</th>
<th>For Dispatch</th>
</tr>
</thead>
<tbody>
<% details[:daily].each do |date, for_dispatch| %>
<% if details %>
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<td><%= date %></td>
<td><%= for_dispatch %></td>
<th>Date</th>
<th>For Dispatch</th>
</tr>
<% end %>
</tbody>
</table>
</thead>
<tbody>
<% details[:daily].each do |date, for_dispatch| %>
<tr>
<td><%= date %></td>
<td><%= for_dispatch %></td>
</tr>
<% end %>
</tbody>
</table>

<p class="table_metadata">
Metadata:
<span class="badge">
Schema version: <%= details[:schema_version] %>
</span>
<p class="table_metadata">
Metadata:
<span class="badge">
Schema version: <%= details[:schema_version] %>
</span>

<span class="badge badge-<%= details[:state] == 'loaded' ? 'success' : 'warning' %>">
State: <%= details[:state] %>
</span>
</p>
</div>
<span class="badge">
Reported at:&nbsp;
<%== relative_time(details[:dispatched_at]) %>
</span>

<span class="badge badge-<%= details[:state] == 'loaded' ? 'success' : 'warning' %>">
State: <%= details[:state] %>
</span>
</p>
</div>
<% else %>
<div class="mb-3">
<%== alert_warning 'No state information for this partition is available.' %>
</div>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# frozen_string_literal: true

RSpec.describe_current do
subject(:app) { Karafka::Web::Pro::Ui::App }

describe 'scheduled_messages/ path redirect' do
context 'when visiting the scheduled_messages/ path without type indicator' do
before { get 'scheduled_messages' }

it 'expect to redirect to running schedules page' do
expect(response.status).to eq(302)
expect(response.headers['location']).to include('scheduled_messages/schedules')
end
end
end

describe '#index' do
let(:no_groups) { 'We are unable to display data related to scheduled messages' }

context 'when there are no schedules in routes nor any topics' do
before { get 'scheduled_messages/schedules' }

it do
expect(response).to be_ok
expect(body).to include(no_groups)
expect(body).to include(breadcrumbs)
expect(body).not_to include(pagination)
expect(body).not_to include(support_message)
end
end

context 'when there are schedules in routes but not created' do
before do
draw_routes do
scheduled_messages('not_existing')
end

get 'scheduled_messages/schedules'
end

it do
expect(response).to be_ok
expect(body).to include(no_groups)
expect(body).to include(breadcrumbs)
expect(body).not_to include(pagination)
expect(body).not_to include(support_message)
end
end

context 'when there is one schedule and routes exist' do
let(:messages_topic) { create_topic }
let(:states_topic) { create_topic(topic_name: "#{messages_topic}_states") }

before do
states_topic
messages_topic_ref = messages_topic

draw_routes do
scheduled_messages(messages_topic_ref)
end

get 'scheduled_messages/schedules'
end

it do
expect(response).to be_ok
expect(body).to include(messages_topic)
expect(body).to include(breadcrumbs)
expect(body).not_to include(no_groups)
expect(body).not_to include(pagination)
expect(body).not_to include(support_message)
end
end

context 'when there are many schedules and routes exist' do
let(:messages_topic1) { create_topic }
let(:states_topic1) { create_topic(topic_name: "#{messages_topic1}_states") }
let(:messages_topic2) { create_topic }
let(:states_topic2) { create_topic(topic_name: "#{messages_topic2}_states") }

before do
states_topic1
messages_topic_ref1 = messages_topic1
states_topic2
messages_topic_ref2 = messages_topic2

draw_routes do
scheduled_messages(messages_topic_ref1)
scheduled_messages(messages_topic_ref2)
end

get 'scheduled_messages/schedules'
end

it do
expect(response).to be_ok
expect(body).to include(messages_topic1)
expect(body).to include(messages_topic2)
expect(body).to include(breadcrumbs)
expect(body).not_to include(no_groups)
expect(body).not_to include(pagination)
expect(body).not_to include(support_message)
end
end

pending
end
end

0 comments on commit 9d28ea9

Please sign in to comment.