Permalink
Browse files

simplify stuff

  • Loading branch information...
1 parent 09c7db1 commit abe8cead109200797df45951c37080db15542410 @svenfuchs svenfuchs committed Jan 23, 2013
View
@@ -6,4 +6,3 @@ log/*
*.class
.rbenv-version
.rbenv-gemsets
-bin/
View
@@ -21,6 +21,7 @@ gem 'sidekiq'
gem 'hot_bunnies', '~> 1.4.0.pre4'
gem 'jruby-openssl', '~> 0.7.7'
+# see http://www.ruby-forum.com/topic/4409725
gem 'activerecord-jdbcpostgresql-adapter', '= 1.2.2.1'
gem 'coder', github: 'rkh/coder'
View
@@ -42,7 +42,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
- revision: 871129e3b8002b8c6299ad0dd04e74a7632fc148
+ revision: e428d0b42fad2834ad187c9b3860bb77ec7d13c9
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.11)
@@ -71,7 +71,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-support.git
- revision: cf916e10949db43ce6f2b6f86082b367f04acfcd
+ revision: ff712aca1083a588974f835a84c574e6976aeb29
specs:
travis-support (0.0.1)
View
@@ -1 +1 @@
-hub: bin/thor travis:hub:start
+hub: ./bin/hub
View
@@ -1,6 +0,0 @@
-$: << File.expand_path('../lib', __FILE__)
-$stdout.sync = true
-
-require 'bundler/setup'
-require 'travis/hub/cli'
-
View
@@ -0,0 +1,18 @@
+#! /usr/bin/env ruby
+
+$stdout.sync = true
+
+$: << 'lib'
+
+require 'bundler/setup'
+require 'travis/hub'
+require 'core_ext/module/load_constants'
+
+[Travis::Hub, Travis].each do |target|
+ target.load_constants!(:skip => [/::AssociationCollection$/], debug: false)
+end
+
+app = Travis::Hub.new
+app.setup
+app.run
+
View
@@ -1,68 +1,60 @@
require 'multi_json'
-require 'benchmark'
-require 'active_support/core_ext/float/rounding'
-require 'core_ext/kernel/run_periodically'
-require 'core_ext/hash/compact'
require 'travis'
-require 'travis/support'
+require 'core_ext/kernel/run_periodically'
$stdout.sync = true
module Travis
class Hub
- autoload :Handler, 'travis/hub/handler'
- autoload :Instrument, 'travis/hub/instrument'
- autoload :Error, 'travis/hub/error'
- autoload :Queues, 'travis/hub/queues'
-
- include Logging
+ autoload :Error, 'travis/hub/error'
+ autoload :Queue, 'travis/hub/queue'
- class << self
- def start
- setup
- prune_workers
- enqueue_jobs
+ extend Instrumentation
- Travis::Hub::Queues.subscribe
- end
-
- protected
+ def setup
+ Travis::Async.enabled = true
+ Travis::Amqp.config = Travis.config.amqp
- def setup
- Travis::Features.start
+ Travis::Database.connect
+ Travis::Async::Sidekiq.setup(Travis.config.redis.url, Travis.config.sidekiq)
- Travis::Async.enabled = true
- Travis::Amqp.config = Travis.config.amqp
- GH::DefaultStack.options[:ssl] = Travis.config.ssl
+ Travis::Exceptions::Reporter.start
+ Travis::Notification.setup
+ Travis::Addons.register
- Travis.config.update_periodically
- Travis::Memory.new(:hub).report_periodically if Travis.env == 'production'
+ Travis::Memory.new(:hub).report_periodically if Travis.env == 'production'
+ NewRelic.start if File.exists?('config/newrelic.yml')
- Travis::Exceptions::Reporter.start
- Travis::Notification.setup
- Travis::Addons.register
+ # do we still need these in hub?
+ # Travis::Mailer.setup
+ # GH::DefaultStack.options[:ssl] = Travis.config.ssl
+ end
- Travis::Database.connect
- Travis::Mailer.setup
- Travis::Async::Sidekiq.setup(Travis.config.redis.url, Travis.config.sidekiq)
+ def run
+ enqueue_jobs
+ Queue.subscribe(&method(:handle))
+ end
- NewRelic.start if File.exists?('config/newrelic.yml')
- end
+ private
- def prune_workers
- run_periodically(Travis.config.workers.prune.interval, &::Worker.method(:prune))
+ def handle(event, payload)
+ ActiveRecord::Base.cache do
+ Travis.run_service(:update_job, event: event.to_s.split(':').last, data: payload)
end
+ end
- def enqueue_jobs
- run_periodically(Travis.config.queue.interval) do
- Travis.run_service(:enqueue_jobs) unless Travis::Features.feature_active?(:travis_enqueue)
- end
+ def enqueue_jobs
+ run_periodically(Travis.config.queue.interval) do
+ Travis.run_service(:enqueue_jobs) unless Travis::Features.feature_active?(:travis_enqueue)
end
+ end
- # def cleanup_jobs
- # run_periodically(Travis.config.jobs.retry.interval, &::Job.method(:cleanup))
- # end
- end
+ # class Instrument < Travis::Notification::Instrument
+ # def update_completed
+ # publish(msg: %(for #<Job id="#{target.payload['id']}">), event: target.event, payload: target.payload)
+ # end
+ # end
+ # Instrument.attach_to(self)
end
end
View
@@ -1,30 +0,0 @@
-require 'bundler/setup'
-require 'travis/hub'
-
-$stdout.sync = true
-
-module Travis
- module Cli
- class Thor < ::Thor
- namespace 'travis:hub'
-
- desc 'start', 'Consume AMQP messages from the worker'
- def start
- ENV['ENV'] || 'development'
- preload_constants!
- Travis::Hub.start
- end
-
- protected
-
- def preload_constants!
- require 'core_ext/module/load_constants'
- require 'travis'
-
- [Travis::Hub, Travis].each do |target|
- target.load_constants!(:skip => [/::AssociationCollection$/], :debug => true)
- end
- end
- end
- end
-end
@@ -1,52 +0,0 @@
-module Travis
- class Hub
- class Handler
- autoload :Job, 'travis/hub/handler/job'
-
- include Logging
- extend Instrumentation, NewRelic
-
- class << self
- def handle(event, payload)
- self.for(event, payload).handle
- end
-
- def for(event, payload)
- case event_type(event, payload)
- when /^request/
- Handler::Request.new(event, payload)
- when /^job|state/
- Handler::Job.new(event, payload)
- when /^worker/
- Handler::Worker.new(event, payload)
- when /^sync/
- Handler::Sync.new(event, payload)
- else
- raise "Unknown message type: #{event.inspect}"
- end
- end
-
- def event_type(event, payload)
- (event || extract_event(payload)).to_s
- end
-
- def extract_event(payload)
- warn "Had to extract event from payload: #{payload.inspect}"
- case payload['type']
- when 'pull_request', 'push'
- 'request'
- else
- payload['type']
- end
- end
- end
-
- attr_accessor :event, :payload
-
- def initialize(event, payload)
- @event = event
- @payload = payload
- end
- end
- end
-end
@@ -1,46 +0,0 @@
-require 'travis/logs/services/append'
-
-module Travis
- class Hub
- class Handler
- # Handles updates from test jobs running on the worker, i.e. events
- # like job:test:started, job:test:log and job:test:finished
- class Job < Handler
- def handle
- case event
- when 'job:test:log'
- log
- else
- update
- end
- end
-
- protected
-
- def job
- @job ||= ::Job.find(payload['id'])
- end
-
- def update
- Travis.run_service(:update_job, event: event.to_s.split(':').last, data: payload)
- end
- instrument :update
- new_relic :update
-
- def log
- if Travis::Features.feature_active?(:travis_logs)
- # TODO hot compat, remove once workers publish to "reporting.jobs.logs" directly
- publisher = Travis::Amqp::Publisher.jobs('logs')
- publisher.publish(:data => payload, :uuid => Travis.uuid)
- else
- Travis.run_service(:logs_append, data: payload)
- end
- end
- instrument :log
- new_relic :log
-
- Travis::Hub::Instrument::Handler::Job.attach_to(self)
- end
- end
- end
-end
@@ -1,25 +0,0 @@
-module Travis
- class Hub
- class Instrument
- module Handler
- class Job < Travis::Notification::Instrument
- def update_completed
- publish(
- :msg => %(for #<Job id="#{target.payload['id']}">),
- :event => target.event,
- :payload => target.payload
- )
- end
-
- def log_completed
- # publish(
- # :msg => %(for #<Job id="#{target.payload['id']}">),
- # :event => target.event,
- # :payload => target.payload
- # )
- end
- end
- end
- end
- end
-end
@@ -1,22 +0,0 @@
-require 'active_support/notifications'
-require 'metriks'
-
-module Travis
- class Hub
- class Metrics
- delegate :subscribe, :to => ActionSupport::Notifications
-
- def self.setup_subscriptions
- new.setup_subscriptions
- end
-
- def setup_subscriptions
- subscribe(/(load|http)\.gh/) do |*args|
- name, start, ending, transaction_id, payload = *args
- time = ending - start
- Metriks.timer(name).update(time)
- end
- end
- end
- end
-end
Oops, something went wrong.

0 comments on commit abe8cea

Please sign in to comment.