mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-05 10:56:11 +02:00
Use ActiveJob::Base to ride on Rails
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
parent
281bd89d27
commit
2f1820d04f
@ -19,7 +19,7 @@ class MiscController < ApplicationController
|
||||
end
|
||||
|
||||
def upgrading_status
|
||||
if FluentdUiRestart::LOCK.present?
|
||||
if FluentdUiRestartJob::LOCK.present?
|
||||
return render text: "updating"
|
||||
end
|
||||
|
||||
@ -73,6 +73,6 @@ class MiscController < ApplicationController
|
||||
end
|
||||
|
||||
def update!
|
||||
FluentdUiRestart.new.async.perform
|
||||
FluentdUiRestart.perform_later
|
||||
end
|
||||
end
|
||||
|
||||
@ -17,27 +17,27 @@ class PluginsController < ApplicationController
|
||||
|
||||
def install
|
||||
params[:plugins].each do |gem_name|
|
||||
GemInstaller.new.async.perform(gem_name)
|
||||
GemInstallerJob.perform_later(gem_name)
|
||||
end
|
||||
redirect_to plugins_path
|
||||
end
|
||||
|
||||
def uninstall
|
||||
params[:plugins].each do |gem_name|
|
||||
GemUninstaller.new.async.perform(gem_name)
|
||||
GemUninstallerJob.perform_later(gem_name)
|
||||
end
|
||||
redirect_to plugins_path
|
||||
end
|
||||
|
||||
def upgrade
|
||||
GemInstaller.new.async.perform(params[:plugins][:name], params[:plugins][:version])
|
||||
GemInstallerJob.perform_later(params[:plugins][:name], params[:plugins][:version])
|
||||
redirect_to plugins_path
|
||||
end
|
||||
|
||||
def bulk_upgrade
|
||||
params[:plugins].each do |gem_name|
|
||||
pl = Plugin.new(gem_name: gem_name)
|
||||
GemInstaller.new.async.perform(gem_name, pl.latest_version)
|
||||
GemInstallerJob.perform_later(gem_name, pl.latest_version)
|
||||
end
|
||||
redirect_to plugins_path
|
||||
end
|
||||
|
||||
10
app/jobs/all_plugin_check_update_job.rb
Normal file
10
app/jobs/all_plugin_check_update_job.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class AllPluginCheckUpdateJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(*args)
|
||||
Plugin.installed.each do |pl|
|
||||
GemUpdateCheckJob.perform_later(pl.gem_name)
|
||||
end
|
||||
later(3600) # will be checked every hour
|
||||
end
|
||||
end
|
||||
2
app/jobs/application_job.rb
Normal file
2
app/jobs/application_job.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class ApplicationJob < ActiveJob::Base
|
||||
end
|
||||
@ -1,5 +1,5 @@
|
||||
class FluentdUiRestart
|
||||
include SuckerPunch::Job
|
||||
class FluentdUiRestartJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
LOCK = []
|
||||
|
||||
@ -20,7 +20,7 @@ class FluentdUiRestart
|
||||
lock!
|
||||
|
||||
# NOTE: install will be failed before released fluentd-ui gem
|
||||
SuckerPunch.logger.info "[restart] install new fluentd-ui"
|
||||
logger.info "[restart] install new fluentd-ui"
|
||||
Plugin.new(gem_name: "fluentd-ui").install!
|
||||
|
||||
if Rails.env.production?
|
||||
@ -29,7 +29,7 @@ class FluentdUiRestart
|
||||
cmd = %W(bundle exec rails s)
|
||||
end
|
||||
|
||||
SuckerPunch.logger.info "[restart] will restart"
|
||||
logger.info "[restart] will restart"
|
||||
Bundler.with_clean_env do
|
||||
restarter = "#{Rails.root}/bin/fluentd-ui-restart"
|
||||
Process.spawn(*[restarter, $$.to_s, *cmd, *ARGV]) && Process.kill(:TERM, $$)
|
||||
@ -1,5 +1,5 @@
|
||||
class FluentdUiUpdateCheck
|
||||
include SuckerPunch::Job
|
||||
class FluentdUiUpdateCheckJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform
|
||||
pl = Plugin.new(gem_name: "fluentd-ui")
|
||||
@ -8,8 +8,4 @@ class FluentdUiUpdateCheck
|
||||
end
|
||||
later(3600) # will be checked every hour
|
||||
end
|
||||
|
||||
def later(sec)
|
||||
after(sec) { perform }
|
||||
end
|
||||
end
|
||||
@ -1,6 +1,5 @@
|
||||
class GemInstaller
|
||||
include SuckerPunch::Job
|
||||
workers 16
|
||||
class GemInstallerJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(gem_name, version = nil)
|
||||
SuckerPunch.logger.info "install #{gem_name} #{version}"
|
||||
@ -9,9 +8,9 @@ class GemInstaller
|
||||
# NOTE: uninstall all versions of `gem_name` then install it for upgrade/downgrade
|
||||
pl.uninstall! if pl.installed?
|
||||
pl.install!
|
||||
SuckerPunch.logger.info "installed #{gem_name} #{version}"
|
||||
logger.info "installed #{gem_name} #{version}"
|
||||
rescue Plugin::GemError
|
||||
SuckerPunch.logger.warn "installing #{gem_name} #{version} is failed"
|
||||
logger.warn "installing #{gem_name} #{version} is failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
14
app/jobs/gem_uninstaller_job.rb
Normal file
14
app/jobs/gem_uninstaller_job.rb
Normal file
@ -0,0 +1,14 @@
|
||||
class GemUninstallerJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(gem_name)
|
||||
logger.info "uninstall #{gem_name}"
|
||||
pl = Plugin.new(gem_name: gem_name)
|
||||
begin
|
||||
pl.uninstall!
|
||||
logger.info "uninstalled #{gem_name}"
|
||||
rescue Plugin::GemError
|
||||
logger.warn "uninstalling #{gem_name} is failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
9
app/jobs/gem_update_check_job.rb
Normal file
9
app/jobs/gem_update_check_job.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class GemUpdateCheckJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(gem_name)
|
||||
logger.info "check #{gem_name} latest version"
|
||||
pl = Plugin.new(gem_name: gem_name)
|
||||
pl.gem_versions!
|
||||
end
|
||||
end
|
||||
@ -1,14 +0,0 @@
|
||||
class AllPluginCheckUpdate
|
||||
include SuckerPunch::Job
|
||||
|
||||
def perform
|
||||
Plugin.installed.each do |pl|
|
||||
GemUpdateCheck.new.async.perform(pl.gem_name)
|
||||
end
|
||||
later(3600) # will be checked every hour
|
||||
end
|
||||
|
||||
def later(sec)
|
||||
after(sec) { perform }
|
||||
end
|
||||
end
|
||||
@ -1,15 +0,0 @@
|
||||
class GemUninstaller
|
||||
include SuckerPunch::Job
|
||||
workers 16
|
||||
|
||||
def perform(gem_name)
|
||||
SuckerPunch.logger.info "uninstall #{gem_name}"
|
||||
pl = Plugin.new(gem_name: gem_name)
|
||||
begin
|
||||
pl.uninstall!
|
||||
SuckerPunch.logger.info "uninstalled #{gem_name}"
|
||||
rescue Plugin::GemError
|
||||
SuckerPunch.logger.warn "uninstalling #{gem_name} is failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,10 +0,0 @@
|
||||
class GemUpdateCheck
|
||||
include SuckerPunch::Job
|
||||
workers 16
|
||||
|
||||
def perform(gem_name)
|
||||
SuckerPunch.logger.info "check #{gem_name} latest version"
|
||||
pl = Plugin.new(gem_name: gem_name)
|
||||
pl.gem_versions!
|
||||
end
|
||||
end
|
||||
@ -35,7 +35,9 @@ module FluentdUi
|
||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||
config.i18n.default_locale = 'en'
|
||||
config.autoload_paths += %W(#{config.root}/app/workers #{config.root}/lib)
|
||||
config.autoload_paths += %W(#{config.root}/lib)
|
||||
|
||||
config.active_job.queue_adapter = :sucker_punch
|
||||
|
||||
# NOTE: currently, fluentd-ui does not using ActiveRecord, and using Time.now instead of Time.zone.now for each different TZ for users.
|
||||
# If AR will be used, please comment in and check timezone.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
unless Rails.env.test?
|
||||
unless FluentdUI.td_agent_ui?
|
||||
# td-agent-ui shouldn't auto update
|
||||
FluentdUiUpdateCheck.new.async.perform
|
||||
FluentdUiUpdateCheckJob.perform_later
|
||||
end
|
||||
end
|
||||
|
||||
@ -1 +1 @@
|
||||
AllPluginCheckUpdate.new.async.perform
|
||||
AllPluginCheckUpdateJob.perform_later
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user