Permalink
Browse files

Merge commit '16d3136f371a004d3504c61cb760ebc910ea79c5' into HEAD

  • Loading branch information...
2 parents b1099df + 16d3136 commit dc1d03abb90713e34175365e44f6b017862edb6c Jenkins committed May 29, 2012
View
@@ -13,7 +13,6 @@ gem 'formtastic', git: 'git://github.com/justinfrench/formtastic.git', branch: '
gem 'formtastic-bootstrap', git: 'git://github.com/cgunther/formtastic-bootstrap.git', branch: 'bootstrap-2'
gem 'stomp'
gem 'marples', '~> 1.0'
-gem 'daemonette', :git => 'git@github.com:alphagov/daemonette.git'
gem 'whenever'
gem 'ansi'
gem 'gelf'
View
@@ -15,12 +15,6 @@ GIT
formtastic (2.1.1)
actionpack (~> 3.0)
-GIT
- remote: git@github.com:alphagov/daemonette.git
- revision: 8179408a2db8f2e882965a2b95ddfc4cdf5230f3
- specs:
- daemonette (0.1.0)
-
GEM
remote: http://rubygems.org/
remote: https://gems.gemfury.com/vo6ZrmjBQu5szyywDszE/
@@ -279,7 +273,6 @@ DEPENDENCIES
ci_reporter
colorize (~> 0.5.8)
cucumber-rails
- daemonette!
database_cleaner
exception_notification
factory_girl
View
@@ -1,38 +0,0 @@
-class AbstractListener
-
- def initialize(messenger = Messenger.instance.client, logger = Rails.logger)
- @messenger = messenger
- @logger = logger
- end
- attr_reader :messenger, :logger
-
- def listen
- Signal.trap('TERM') do
- client.close
- exit
- end
-
- self.class.listeners.each do |messages, handler|
- messenger.when *messages do |message|
- logger.info "Received message #{message}"
- begin
- handler.call(message, logger)
- rescue => e
- logger.error "Unable to process message #{message}"
- logger.error [e.message, e.backtrace].flatten.join("\n")
- end
- logger.info "Finished processing message #{message}"
- end
- end
-
- messenger.join
- end
-
- def self.listen(*messages, &handler)
- listeners << [messages, handler]
- end
-
- def self.listeners
- @listeners ||= []
- end
-end
View
@@ -1,16 +0,0 @@
-require "abstract_listener"
-
-class ContactListener < AbstractListener
-
- listen 'contactotron', '*', 'created' do |message, logger|
- logger.info "Creating contact #{message['id']}"
- contact = Contact.find_or_initialize_by_contactotron_id(message['id'])
- contact.update_from_contactotron
- end
-
- listen 'contactotron', '*', 'updated' do |message, logger|
- logger.info "Updating contact #{message['id']}"
- contact = Contact.find_or_initialize_by_contactotron_id(message['id'])
- contact.update_from_contactotron
- end
-end
View
@@ -1,22 +0,0 @@
-require "abstract_listener"
-
-class NeedListener < AbstractListener
-
- listen 'need-o-tron', 'needs', 'updated' do |need, logger|
- logger.info "Found need #{need}"
- logger.info "Processing need `#{need['title']}`"
-
- artefact = Artefact.find_by_need_id(need['id'])
- logger.info "Found artefact `#{artefact.name}` in Panopticon"
-
- require 'gds_api/needotron'
- api = GdsApi::Needotron.new(Plek.current.environment)
- need_data = api.need_by_id(need['id'])
- logger.info "Getting need information from `#{need['id']}`"
-
- artefact.department = need_data.writing_team.name rescue nil
- artefact.fact_checkers = need_data.fact_checkers.collect{ |e| e.fact_checker.email }.join(', ')
- artefact.save!
- logger.info "----> Saved `#{artefact.name}` with department `#{artefact.department}` and fact checkers `#{artefact.fact_checkers}`"
- end
-end
View
@@ -1,22 +0,0 @@
-namespace :messenger do
- desc 'Listen for messages so that panopticon can remain up to date'
- task :listen do
- Daemonette.run("panopticon_deleted_publication_listener") do
- require "deleted_publication_listener.rb"
- Rake::Task["environment"].invoke
- DeletedPublicationListener.new.listen
- end
-
- Daemonette.run('panopticon_contact_listener') do
- require 'contact_listener.rb'
- Rake::Task['environment'].invoke
- ContactListener.new.listen
- end
-
- Daemonette.run('panopticon_need_listener') do
- require 'need_listener.rb'
- Rake::Task['environment'].invoke
- NeedListener.new.listen
- end
- end
-end
@@ -1,37 +0,0 @@
-require "test_helper"
-require "contact_listener"
-
-class ContactListenerTest < ActiveSupport::TestCase
- def mock_messenger
- mock("messenger").tap { |messenger|
- messenger.stubs(:join)
- messenger.stubs(:when)
- }
- end
-
- test "should create a contact" do
- message = {"id" => 1234}
-
- messenger = mock_messenger
- messenger.expects(:when).with("contactotron", "*", "created").yields(message)
-
- contact = mock("contact")
- contact.expects(:update_from_contactotron)
- Contact.expects(:find_or_initialize_by_contactotron_id).with(1234).returns(contact)
-
- ContactListener.new(messenger, stub_everything).listen
- end
-
- test "should update a contact" do
- message = {"id" => 1234}
-
- messenger = mock_messenger
- messenger.expects(:when).with("contactotron", "*", "updated").yields(message)
-
- contact = mock("contact")
- contact.expects(:update_from_contactotron)
- Contact.expects(:find_or_initialize_by_contactotron_id).with(1234).returns(contact)
-
- ContactListener.new(messenger, stub_everything).listen
- end
-end
@@ -1,39 +0,0 @@
-require "test_helper"
-require "need_listener"
-require "gds_api/needotron"
-
-class NeedListenerTest < ActiveSupport::TestCase
- def mock_messenger
- mock("messenger").tap { |messenger|
- messenger.stubs(:join)
- messenger.stubs(:when)
- }
- end
-
- test "should update artefact when need is updated" do
- message = {"id" => 1234, "title" => "TITLE"}
-
- messenger = mock_messenger
- messenger.expects(:when).with("need-o-tron", "needs", "updated").yields(message)
-
- artefact = Artefact.new
- artefact.expects(:save!)
- Artefact.expects(:find_by_need_id).with(1234).returns(artefact)
-
- need_data = mock("need_data")
- need_data.stubs(:writing_team).returns(stub(:name => "WRITING TEAM NAME"))
- need_data.stubs(:fact_checkers).returns([
- stub(:fact_checker => stub(:email => "A")),
- stub(:fact_checker => stub(:email => "B"))
- ])
-
- api = mock("api")
- api.expects(:need_by_id).with(1234).returns(need_data)
- GdsApi::Needotron.expects(:new).returns(api)
-
- NeedListener.new(messenger, stub_everything).listen
-
- assert_equal "WRITING TEAM NAME", artefact.department
- assert_equal "A, B", artefact.fact_checkers
- end
-end

0 comments on commit dc1d03a

Please sign in to comment.