Skip to content

Commit

Permalink
make exclusive to solid_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe committed Nov 11, 2024
1 parent cf50b95 commit 893dfcf
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module MissionControl::Jobs::AdapterFeatures
extend ActiveSupport::Concern

included do
helper_method :supported_job_statuses, :queue_pausing_supported?, :workers_exposed?, :recurring_tasks_supported?
helper_method :supported_job_statuses, :queue_pausing_supported?, :workers_exposed?, :supports_dashboard?, :recurring_tasks_supported?
end

private
Expand All @@ -21,4 +21,8 @@ def workers_exposed?
def recurring_tasks_supported?
MissionControl::Jobs::Current.server.queue_adapter.supports_recurring_tasks?
end

def supports_dashboard?
MissionControl::Jobs::Current.server.queue_adapter.supports_dashboard?
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
class MissionControl::Jobs::InternalApi::NavigationController < MissionControl::Jobs::ApplicationController
include ActionView::Helpers::NumberHelper
include MissionControl::Jobs::NavigationHelper


def index
@navigation_sections = navigation_sections

render partial: "layouts/mission_control/jobs/navigation_update", locals: {
section: params[:section].to_sym
}
Expand Down
9 changes: 6 additions & 3 deletions app/helpers/mission_control/jobs/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ module MissionControl::Jobs::NavigationHelper
attr_reader :page_title, :current_section

def navigation_sections
{ dashboard: [ "Dashboard", application_dashboard_index_path(@application) ] }.tap do |sections|
sections[:queues] = [ "Queues", application_queues_path(@application) ]
sections = { }
sections[:dashboard] = [ "Dashboard", application_dashboard_index_path(@application) ] if supports_dashboard?

sections.tap do |sections|
sections[:queues] = [ "Queues", application_queues_path(@application) ]

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

sections[:workers] = [ "Workers", application_workers_path(@application) ] if workers_exposed?

sections[:recurring_tasks] = [ "Recurring tasks", application_recurring_tasks_path(@application) ] if recurring_tasks_supported?
end
end
Expand Down
46 changes: 35 additions & 11 deletions app/views/layouts/mission_control/jobs/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
</div>

<script>
if (typeof navigationInterval === "undefined") {
var navigationInterval = null;
}

document.addEventListener("turbo:load", () => {
if (!window.Navigation || typeof window.Navigation.currentSection === 'undefined') {
window.Navigation = {
Expand All @@ -19,19 +23,39 @@
}
};

setInterval(() => {
fetch(`/jobs/applications/solidqueueusage/internal_api/navigation?section=${window.Navigation.currentSection}`)
.then(response => response.text())
.then(html => {
const navigationSections = document.querySelector('#navigation-sections');
if (navigationSections) {
navigationSections.innerHTML = html;
}
})
.catch(error => console.error("Error fetching navigation update:", error));
}, 5000);
startNavigationInterval();
} else {
window.Navigation.currentSection = "<%= @current_section %>";
}
});

document.addEventListener("turbo:visit", () => {
clearInterval(navigationInterval);
startNavigationInterval();
});

function startNavigationInterval() {
let urlParams = new URLSearchParams(window.location.search);
// if (urlParams.get('server_id') !== 'solid_queue') return;

navigationInterval = setInterval(() => {
urlParams = new URLSearchParams(window.location.search);
fetch(`<%= application_internal_api_navigation_index_path %>&server_id=${urlParams.get('server_id')}&section=${window.Navigation.currentSection}`)
.then(response => response.text())
.then(html => {
if (urlParams.get('server_id') !== 'solid_queue') {
console.log(urlParams.get('server_id'))
return;
}

console.log("Update navbar")

const navigationSections = document.querySelector('#navigation-sections');
if (navigationSections) {
navigationSections.innerHTML = html;
}
})
.catch(error => console.error("Error fetching navigation update:", error));
}, 5000);
}
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ul>
<% navigation_sections.each do |key, (label, url)| %>
<% @navigation_sections.each do |key, (label, url)| %>
<li class="<%= "is-active" if key == section %>">
<%= link_to label, url %>
</li>
Expand Down
18 changes: 8 additions & 10 deletions app/views/layouts/mission_control/jobs/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
<%= javascript_importmap_tags "application", importmap: MissionControl::Jobs.importmap %>
</head>
<body>

<section class="section">
<div class="container">
<%= render "layouts/mission_control/jobs/application_selection" %>
<%= render "layouts/mission_control/jobs/flash" %>
<%= render "layouts/mission_control/jobs/navigation" %>
<%= yield %>
</div>
</section>

<section class="section">
<div class="container">
<%= render "layouts/mission_control/jobs/application_selection" %>
<%= render "layouts/mission_control/jobs/flash" %>
<%= render "layouts/mission_control/jobs/navigation" %>
<%= yield %>
</div>
</section>
</body>
</html>
5 changes: 1 addition & 4 deletions app/views/mission_control/jobs/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,14 @@
chart = new Chart(ctx, config);

function handleSelectUptime(value) {
// console.log("Update Uptime to " + value);
uptime = value;
clearInterval(uptimeInterval);
uptimeInterval = setInterval(() => updateChartData(), value * 1000);
}

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

const data = await response.json();
Expand Down Expand Up @@ -163,11 +162,9 @@
uptimeInterval = setInterval(() => updateChartData(), 5000);
updateChartData();

// Exponha a função no escopo global
window.handleSelectUptime = handleSelectUptime;
});

// Limpa o gráfico e o intervalo antes de sair da página
document.addEventListener("turbo:before-render", () => {
if (uptimeInterval != null) {
clearInterval(uptimeInterval);
Expand Down
4 changes: 4 additions & 0 deletions lib/active_job/queue_adapters/resque_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def supports_queue_pausing?
defined?(ResquePauseHelper)
end

def supports_dashboard?
false
end

private
attr_reader :redis

Expand Down
4 changes: 4 additions & 0 deletions lib/mission_control/jobs/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def supports_queue_pausing?
true
end

def supports_dashboard?
true
end

def exposes_workers?
false
end
Expand Down

0 comments on commit 893dfcf

Please sign in to comment.