Skip to content

Commit 893dfcf

Browse files
author
Felipe
committed
make exclusive to solid_queue
1 parent cf50b95 commit 893dfcf

File tree

9 files changed

+70
-30
lines changed

9 files changed

+70
-30
lines changed

app/controllers/concerns/mission_control/jobs/adapter_features.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module MissionControl::Jobs::AdapterFeatures
22
extend ActiveSupport::Concern
33

44
included do
5-
helper_method :supported_job_statuses, :queue_pausing_supported?, :workers_exposed?, :recurring_tasks_supported?
5+
helper_method :supported_job_statuses, :queue_pausing_supported?, :workers_exposed?, :supports_dashboard?, :recurring_tasks_supported?
66
end
77

88
private
@@ -21,4 +21,8 @@ def workers_exposed?
2121
def recurring_tasks_supported?
2222
MissionControl::Jobs::Current.server.queue_adapter.supports_recurring_tasks?
2323
end
24+
25+
def supports_dashboard?
26+
MissionControl::Jobs::Current.server.queue_adapter.supports_dashboard?
27+
end
2428
end

app/controllers/mission_control/jobs/internal_api/navigation_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
class MissionControl::Jobs::InternalApi::NavigationController < MissionControl::Jobs::ApplicationController
2+
include ActionView::Helpers::NumberHelper
3+
include MissionControl::Jobs::NavigationHelper
4+
5+
26
def index
7+
@navigation_sections = navigation_sections
8+
39
render partial: "layouts/mission_control/jobs/navigation_update", locals: {
410
section: params[:section].to_sym
511
}

app/helpers/mission_control/jobs/navigation_helper.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ module MissionControl::Jobs::NavigationHelper
22
attr_reader :page_title, :current_section
33

44
def navigation_sections
5-
{ dashboard: [ "Dashboard", application_dashboard_index_path(@application) ] }.tap do |sections|
6-
sections[:queues] = [ "Queues", application_queues_path(@application) ]
5+
sections = { }
6+
sections[:dashboard] = [ "Dashboard", application_dashboard_index_path(@application) ] if supports_dashboard?
7+
8+
sections.tap do |sections|
79
sections[:queues] = [ "Queues", application_queues_path(@application) ]
810

911
supported_job_statuses.without(:pending).each do |status|
10-
sections[navigation_section_for_status(status)] = [ "#{status.to_s.titleize} jobs (#{jobs_count_with_status(status)})", application_jobs_path(@application, status) ]
12+
sections[navigation_section_for_status(status)] = [ "#{status.to_s.titleize} jobs (#{jobs_count_with_status(status)})", application_jobs_path(@application, status) ]
1113
end
1214

1315
sections[:workers] = [ "Workers", application_workers_path(@application) ] if workers_exposed?
16+
1417
sections[:recurring_tasks] = [ "Recurring tasks", application_recurring_tasks_path(@application) ] if recurring_tasks_supported?
1518
end
1619
end

app/views/layouts/mission_control/jobs/_navigation.html.erb

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
</div>
1010

1111
<script>
12+
if (typeof navigationInterval === "undefined") {
13+
var navigationInterval = null;
14+
}
15+
1216
document.addEventListener("turbo:load", () => {
1317
if (!window.Navigation || typeof window.Navigation.currentSection === 'undefined') {
1418
window.Navigation = {
@@ -19,19 +23,39 @@
1923
}
2024
};
2125

22-
setInterval(() => {
23-
fetch(`/jobs/applications/solidqueueusage/internal_api/navigation?section=${window.Navigation.currentSection}`)
24-
.then(response => response.text())
25-
.then(html => {
26-
const navigationSections = document.querySelector('#navigation-sections');
27-
if (navigationSections) {
28-
navigationSections.innerHTML = html;
29-
}
30-
})
31-
.catch(error => console.error("Error fetching navigation update:", error));
32-
}, 5000);
26+
startNavigationInterval();
3327
} else {
3428
window.Navigation.currentSection = "<%= @current_section %>";
3529
}
3630
});
31+
32+
document.addEventListener("turbo:visit", () => {
33+
clearInterval(navigationInterval);
34+
startNavigationInterval();
35+
});
36+
37+
function startNavigationInterval() {
38+
let urlParams = new URLSearchParams(window.location.search);
39+
// if (urlParams.get('server_id') !== 'solid_queue') return;
40+
41+
navigationInterval = setInterval(() => {
42+
urlParams = new URLSearchParams(window.location.search);
43+
fetch(`<%= application_internal_api_navigation_index_path %>&server_id=${urlParams.get('server_id')}&section=${window.Navigation.currentSection}`)
44+
.then(response => response.text())
45+
.then(html => {
46+
if (urlParams.get('server_id') !== 'solid_queue') {
47+
console.log(urlParams.get('server_id'))
48+
return;
49+
}
50+
51+
console.log("Update navbar")
52+
53+
const navigationSections = document.querySelector('#navigation-sections');
54+
if (navigationSections) {
55+
navigationSections.innerHTML = html;
56+
}
57+
})
58+
.catch(error => console.error("Error fetching navigation update:", error));
59+
}, 5000);
60+
}
3761
</script>

app/views/layouts/mission_control/jobs/_navigation_update.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ul>
2-
<% navigation_sections.each do |key, (label, url)| %>
2+
<% @navigation_sections.each do |key, (label, url)| %>
33
<li class="<%= "is-active" if key == section %>">
44
<%= link_to label, url %>
55
</li>

app/views/layouts/mission_control/jobs/application.html.erb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
<%= javascript_importmap_tags "application", importmap: MissionControl::Jobs.importmap %>
1515
</head>
1616
<body>
17-
18-
<section class="section">
19-
<div class="container">
20-
<%= render "layouts/mission_control/jobs/application_selection" %>
21-
<%= render "layouts/mission_control/jobs/flash" %>
22-
<%= render "layouts/mission_control/jobs/navigation" %>
23-
<%= yield %>
24-
</div>
25-
</section>
26-
17+
<section class="section">
18+
<div class="container">
19+
<%= render "layouts/mission_control/jobs/application_selection" %>
20+
<%= render "layouts/mission_control/jobs/flash" %>
21+
<%= render "layouts/mission_control/jobs/navigation" %>
22+
<%= yield %>
23+
</div>
24+
</section>
2725
</body>
2826
</html>

app/views/mission_control/jobs/dashboard/index.html.erb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,14 @@
118118
chart = new Chart(ctx, config);
119119

120120
function handleSelectUptime(value) {
121-
// console.log("Update Uptime to " + value);
122121
uptime = value;
123122
clearInterval(uptimeInterval);
124123
uptimeInterval = setInterval(() => updateChartData(), value * 1000);
125124
}
126125

127126
async function updateChartData() {
128127
try {
129-
const response = await fetch(`<%= application_internal_api_dashboard_index_path %>?uptime=${uptime}`);
128+
const response = await fetch(`<%= application_internal_api_dashboard_index_path %>&uptime=${uptime}`);
130129
if (!response.ok) throw new Error('Network response was not ok');
131130

132131
const data = await response.json();
@@ -163,11 +162,9 @@
163162
uptimeInterval = setInterval(() => updateChartData(), 5000);
164163
updateChartData();
165164

166-
// Exponha a função no escopo global
167165
window.handleSelectUptime = handleSelectUptime;
168166
});
169167

170-
// Limpa o gráfico e o intervalo antes de sair da página
171168
document.addEventListener("turbo:before-render", () => {
172169
if (uptimeInterval != null) {
173170
clearInterval(uptimeInterval);

lib/active_job/queue_adapters/resque_ext.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def supports_queue_pausing?
8585
defined?(ResquePauseHelper)
8686
end
8787

88+
def supports_dashboard?
89+
false
90+
end
91+
8892
private
8993
attr_reader :redis
9094

lib/mission_control/jobs/adapter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def supports_queue_pausing?
2525
true
2626
end
2727

28+
def supports_dashboard?
29+
true
30+
end
31+
2832
def exposes_workers?
2933
false
3034
end

0 commit comments

Comments
 (0)