Actually uninstall plugin

This commit is contained in:
uu59 2014-05-20 13:34:20 +09:00
parent 6eb7e606a6
commit 5adff02889
4 changed files with 43 additions and 12 deletions

View File

@ -24,8 +24,7 @@ class PluginsController < ApplicationController
def uninstall
params[:plugins].each do |gem_name|
pl = Plugin.new(gem_name: gem_name)
pl.uninstall!
GemUninstaller.new.async.perform(gem_name)
end
redirect_to plugins_path
end

View File

@ -31,12 +31,14 @@ class Plugin
# NOTE: do not uninstall gem actually for now. because it is not necessary, and slow job
# NOTE: should uninstall that situation: installed verions is A, self.version is NOT A. only check gem_name.
new_gemfile = ""
File.open(gemfile_path).each_line do |line|
next if line.include?(%Q|gem "#{gem_name}"|)
new_gemfile << line
if gem_uninstall
new_gemfile = ""
File.open(gemfile_path).each_line do |line|
next if line.include?(%Q|gem "#{gem_name}"|)
new_gemfile << line
end
File.open(gemfile_path, "w"){|f| f.write new_gemfile }
end
File.open(gemfile_path, "w"){|f| f.write new_gemfile }
end
def upgrade!(new_version)
@ -121,10 +123,17 @@ class Plugin
fluent_gem("install", gem_name, "-v", version)
end
def gem_uninstall
fluent_gem("uninstall", gem_name, "-x", "-a")
end
def fluent_gem(*commands)
# NOTE: use `fluent-gem` instead of `gem`
unless system(*%W(bundle exec fluent-gem) + commands) # TODO: should grab stdout/stderr
raise GemError, "failed command #{commands.join(" ")}"
Bundler.with_clean_env do
# NOTE: this app is under the Bundler, so call `system` in with_clean_env is Bundler jail breaking
unless system(*%W(fluent-gem) + commands) # TODO: should grab stdout/stderr
raise GemError, "failed command #{commands.join(" ")}"
end
end
true
end

View File

@ -9,9 +9,12 @@ class GemInstaller
pl = Plugin.new(gem_name: gem_name, version: version)
unless WORKING.find{|p| p.gem_name == pl.gem_name}
WORKING.push(pl)
pl.uninstall! if pl.installed?
pl.install!
WORKING.delete(pl)
begin
pl.uninstall! if pl.installed?
pl.install!
ensure
WORKING.delete(pl)
end
end
SuckerPunch.logger.info "installed #{gem_name} #{version}"
end

View File

@ -0,0 +1,20 @@
class GemUninstaller
include SuckerPunch::Job
workers 16
WORKING = []
def perform(gem_name)
SuckerPunch.logger.info "uninstall #{gem_name}"
pl = Plugin.new(gem_name: gem_name)
unless WORKING.find{|p| p.gem_name == pl.gem_name}
WORKING.push(pl)
begin
pl.uninstall!
ensure
WORKING.delete(pl)
end
end
SuckerPunch.logger.info "uninstalled #{gem_name}"
end
end