Fix REXML Exception when using Unicorn or Passenger with XmlRPC. Add XML RPC events logging. Refactor. Improve after_rollback callback. Refs #2162

This commit is contained in:
Pavel Chipiga 2011-10-30 18:46:32 +02:00
parent d8c491f6e1
commit 0c3a044f81
9 changed files with 46 additions and 34 deletions

View File

@ -29,7 +29,7 @@ gem 'unicorn'
# XML-RPC support
# gem 'actionwebservice' #, :git => 'git://github.com/ywen/actionwebservice.git'
gem "rails-xmlrpc"
gem "rails-xmlrpc", :git => 'git://github.com/chipiga/rails-xmlrpc.git'
group :production do
gem "airbrake"

View File

@ -1,3 +1,9 @@
GIT
remote: git://github.com/chipiga/rails-xmlrpc.git
revision: 3cf79e062c65447809209724a0cb8d1ea5af2e57
specs:
rails-xmlrpc (0.3.1)
GIT
remote: git@github.com:warpc/gitolito.git
revision: 8608b9bdfd33e961d9f9d71dd594e62780c074f6
@ -189,7 +195,6 @@ GEM
activesupport (= 3.0.10)
bundler (~> 1.0)
railties (= 3.0.10)
rails-xmlrpc (0.3.2)
rails3-generators (0.17.4)
railties (>= 3.0.0)
railties (3.0.10)
@ -280,7 +285,7 @@ DEPENDENCIES
paperclip (~> 2.3)
pg (~> 0.11.0)
rails (= 3.0.10)
rails-xmlrpc
rails-xmlrpc!
rails3-generators
rspec-rails (~> 2.7.0)
ruby-debug

View File

@ -3,7 +3,8 @@ class RpcController < ApplicationController
before_filter :authenticate_user!
before_filter :check_global_access
before_filter lambda { EventLog.current_controller = self }, :only => :xe_index # should be after auth callback
## Usage example:
#
# require 'xmlrpc/client'
@ -11,27 +12,31 @@ class RpcController < ApplicationController
# client.call("project_versions", 1)
def platforms
ActiveSupport::Notifications.instrument("event_log.observer", :message => 'список платформ')
return Platform.select('id, unixname').where("platform_type = ?", 'main').map(&:attributes)
end
def user_projects
current_user.projects.map{|pr| { :id => pr.id, :unixname => pr.unixname } }
end
def project_versions id
pr = Project.findby_id(id)
return nil if pr.blank?
pr.project_versions.collect { |tag| [tag.name.gsub(/^\w+\./, ""), tag.name] }.select { |pv| pv[1] =~ /^v\./ }
end
def build_status id
BuildList.find_by_id(id).try(:status)
end
def build_packet project_id, repo_id
# TODO: build packet
end
def user_projects
ActiveSupport::Notifications.instrument("event_log.observer", :message => 'список пользовательских проектов')
current_user.projects.map{|p| { :id => p.id, :unixname => p.unixname } }
end
def project_versions id
p = Project.find_by_id(id)
ActiveSupport::Notifications.instrument("event_log.observer", :object => p, :message => "список версий")
return nil if p.blank?
p.project_versions.collect {|tag| [tag.name.gsub(/^\w+\./, ""), tag.name]}.select {|pv| pv[1] =~ /^v\./}
end
def build_status id
bl = BuildList.find_by_id(id)
ActiveSupport::Notifications.instrument("event_log.observer", :object => bl, :message => 'статус сборки')
bl.try(:status) || 'not found'
end
def build_packet project_id, repo_id
# p = Project.find_by_id(project_id); r = Repository.find_by_id(repo_id)
ActiveSupport::Notifications.instrument("event_log.observer", :message => 'сборка пакета')
'unknown' # TODO: build packet
end
end

View File

@ -18,9 +18,9 @@ class EventLog < ActiveRecord::Base
create(attributes) do |el|
el.user = current_controller.current_user
el.ip = current_controller.request.remote_ip
el.protocol = 'web' # TODO pass protocol through controller or calculate by name
el.controller = current_controller.class.to_s
el.action = current_controller.action_name
el.protocol = (el.controller == 'RpcController' ? 'api' : 'web')
end
end

View File

@ -36,7 +36,7 @@ class Project < ActiveRecord::Base
after_create :create_git_repo
before_update :update_git_repo
after_destroy :destroy_git_repo
after_rollback lambda { destroy_git_repo rescue true }
after_rollback lambda { destroy_git_repo rescue true if new_record? }
def project_versions
#tags.collect { |tag| [tag.name, tag.name.gsub(/^\w+\./, "")] }.select { |pv| pv[0] =~ /^v\./ }

View File

@ -11,7 +11,7 @@ class ProjectToRepository < ActiveRecord::Base
after_create lambda { project.xml_rpc_create(repository) }
after_destroy lambda { project.xml_rpc_destroy(repository) }
after_rollback lambda { project.xml_rpc_destroy(repository) rescue true }
after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? }
#def path
# build_path(project.unixname)

View File

@ -2,13 +2,13 @@
require 'rubygems'
require 'xmlrpc/client'
require 'ap' # awesome_print
require 'awesome_print'
# Please correctly fill following vars
@host = 'localhost'
@port = 3000
@user = 'user@email'
@password = ''
@user = 'pchipiga@ya.ru'
@password = '123456'
puts 'PLATFORMS'
client = XMLRPC::Client.new(@host, '/api/xmlrpc', @port, nil, nil, @user, @password, false, 900)

View File

@ -10,6 +10,7 @@ ru:
'devise/sessions_controller': 'Аутентификация пользователей'
'devise/passwords_controller': 'Восстановление пароля'
'users/omniauth_callbacks_controller': 'Внешняя аутентификация пользователей'
rpc_controller: XML RPC
actions:
'devise/sessions_controller':
create: 'вход'
@ -22,6 +23,8 @@ ru:
build_lists_controller:
cancel: 'сборка отменена'
publish: 'сборка опубликована'
rpc_controller:
xe_index: запрос
create: 'создано'
update: 'обновлено'
destroy: 'удалено'

View File

@ -271,11 +271,10 @@ ActiveRecord::Schema.define(:version => 20111029150934) do
create_table "users", :force => true do |t|
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.string "remember_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"