Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add jobs administration #37

Draft
wants to merge 3 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ class AdminController < ApplicationController
end
}

# TODO: remove this endpoint. It's termporary to test the update check functionality
# get "/latestversion" do
# iid = params["iid"]
# ver = params["version"]
#
# latest_ver_info = {
# update_version: "2.5RC3", #"2.6RC1",
# update_available: true,
# notes: "blah blah and more"
# }
# reply MultiJson.dump latest_ver_info
# end

get "/scheduled_jobs" do
reply MultiJson.dump scheduled_jobs_map
end

get "/scheduled_jobs/log" do
log_path = cron_daemon_options[:log_path]
stream_file(log_path)
end

get "/scheduled_jobs/:job/log" do
scheduled_jobs = scheduled_jobs_map
job_name = params["job"]
error 404, "You must provide a valid `job` to retrieve its log" unless scheduled_jobs.has_key?(job_name.to_sym)

log_dir_name = File.dirname(cron_daemon_options[:log_path])
log_file_name = "#{log_dir_name.chomp '/'}/scheduler-#{job_name.gsub '_', '-'}.log"

stream_file(log_file_name)
end

get "/update_info" do
um = NcboCron::Models::UpdateManager.new
Expand Down
107 changes: 107 additions & 0 deletions helpers/admin_jobs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
require 'sinatra/base'

module Sinatra
module Helpers
module AdminJobsHelper

def redis_cron
Redis.new(host: NcboCron.settings.redis_host, port: NcboCron.settings.redis_port, timeout: 30)
end

def cron_daemon_options
cron_settings_json = redis_cron.get "cron:daemon:options"
error 500, "Unable to get CRON daemon options from Redis" if cron_settings_json.nil?
::JSON.parse(cron_settings_json, symbolize_names: true)
end

def scheduled_jobs_map
cron_options = cron_daemon_options

{
parse: {
title: "parse semantic resources",
enabled: cron_options[:enable_processing] || false,
scheduler_type: "every",
schedule: "5m" # this is hardcoded in the scheduler class
},
pull: {
title: "pull remote semantic resources",
enabled: cron_options[:enable_pull] || false,
scheduler_type: "cron",
schedule: cron_options[:pull_schedule]
},
flush: {
title: "flush classes",
enabled: cron_options[:enable_flush] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_flush]
},
warmq: {
title: "warm up queries",
enabled: cron_options[:enable_warmq] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_warmq]
},
mapping_counts: {
title: "mapping counts generation",
enabled: cron_options[:enable_mapping_counts] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_mapping_counts]
},
ontology_analytics: {
title: "semantic resource analytics",
enabled: cron_options[:enable_ontology_analytics] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_ontology_analytics]
},
ontologies_report: {
title: "semantic resources report",
enabled: cron_options[:enable_ontologies_report] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_ontologies_report]
},
index_synchronizer: {
title: "index synchronization",
enabled: cron_options[:enable_index_synchronizer] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_index_synchronizer]
},
spam_deletion: {
title: "spam deletion",
enabled: cron_options[:enable_spam_deletion] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_spam_deletion]
},
obofoundry_sync: {
title: "OBO Foundry synchronization",
enabled: cron_options[:enable_obofoundry_sync] || false,
scheduler_type: "cron",
schedule: cron_options[:cron_obofoundry_sync]
}
}
end

def stream_file(filename)
if !File.exist? filename
stream { |out| out << "" }
else
content_type "text/plain"
stream do |out|
File.open(filename, mode = "r") do |f|
loop do
chunk = f.read 4096
if chunk.nil?
break
else
out << chunk
end
end
end
end
end
end
end
end
end

helpers Sinatra::Helpers::AdminJobsHelper