Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 17, 2011
@djrice djrice remove deprecated usage of ActiveSupport::SecureRandom a620887
@djrice djrice Fix problem where tests did not pass on a clean checkout. Poller test…
… now uses a fresh temp dir for event state rather than the production location.
5dfe03c
View
7 lib/mingle_events/poller.rb
@@ -5,17 +5,18 @@ class Poller
# configured for specified mingle projects. processors_by_project_identifier should
# be a hash where the keys are mingle project identifiers and the values are
# lists of event processors.
- def initialize(mingle_access, processors_by_project_identifier)
+ def initialize(mingle_access, processors_by_project_identifier, state_dir=nil)
@mingle_access = mingle_access
@processors_by_project_identifier = processors_by_project_identifier
+ @state_dir = state_dir
end
# Run a single poll for each project configured with processor(s) and
# broadcast each event to each processor.
- def run_once(options={})
+ def run_once
MingleEvents.log.info("MingleEvents::Poller about to poll once...")
@processors_by_project_identifier.each do |project_identifier, processors|
- fetcher = ProjectEventFetcher.new(project_identifier, @mingle_access)
+ fetcher = ProjectEventFetcher.new(project_identifier, @mingle_access, @state_dir)
fetcher.set_current_state_to_now_if_no_current_state
latest_events = fetcher.fetch_latest.to_a
processors.each{|p| p.process_events(latest_events)}
View
16 lib/mingle_events/project_event_fetcher.rb
@@ -11,7 +11,8 @@ def initialize(project_identifier, mingle_access, state_dir=nil)
@project_identifier = project_identifier
@mingle_access = mingle_access
base_uri = URI.parse(mingle_access.base_url)
- @state_dir = File.expand_path(state_dir || File.join('~', '.mingle_events', base_uri.host, base_uri.port.to_s, project_identifier, 'fetched_events'))
+ @state_dir = state_dir || File.join('~', '.mingle_events', base_uri.host, base_uri.port.to_s)
+ @state_dir = File.expand_path(File.join(@state_dir, project_identifier, 'fetched_events'))
end
# blow away any existing state, when next used to fetch events from mingle
@@ -73,13 +74,12 @@ def last_entry_fetched
# only public to facilitate testing
def update_current_state(oldest_new_entry, most_recent_new_entry)
current_state = load_current_state
- # if most_recent_new_entry
- current_state.merge!(:last_fetched_entry_info_file => file_for_entry(most_recent_new_entry))
- if current_state[:first_fetched_entry_info_file].nil?
- current_state.merge!(:first_fetched_entry_info_file => file_for_entry(oldest_new_entry))
- end
- File.open(current_state_file, 'w'){|out| YAML.dump(current_state, out)}
- # end
+ current_state.merge!(:last_fetched_entry_info_file => file_for_entry(most_recent_new_entry))
+ if current_state[:first_fetched_entry_info_file].nil?
+ current_state.merge!(:first_fetched_entry_info_file => file_for_entry(oldest_new_entry))
+ end
+ FileUtils.mkdir_p(File.dirname(current_state_file))
+ File.open(current_state_file, 'w'){|out| YAML.dump(current_state, out)}
end
# only public to facilitate testing
View
2 test/mingle_events/poller_test.rb
@@ -8,7 +8,7 @@ def test_sends_all_events_to_all_processors
mingle_access = stub_mingle_access
processor_1 = DummyProcessor.new
processor_2 = DummyProcessor.new
- poller = Poller.new(mingle_access, {'atlas' => [processor_1, processor_2]})
+ poller = Poller.new(mingle_access, {'atlas' => [processor_1, processor_2]}, state_folder)
mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml', EMPTY_EVENTS_XML)
poller.run_once
View
4 test/test_helper.rb
@@ -116,13 +116,13 @@ def stub_mingle_access
end
def temp_dir
- path = File.expand_path(File.join(File.dirname(__FILE__), 'tmp', ActiveSupport::SecureRandom.hex(16)))
+ path = File.expand_path(File.join(File.dirname(__FILE__), 'tmp', ::SecureRandom.hex(16)))
FileUtils.mkdir_p(path)
path
end
def temp_file
- File.join(temp_dir, ActiveSupport::SecureRandom.hex(16))
+ File.join(temp_dir, ::SecureRandom.hex(16))
end
class StubMingleAccess

No commit comments for this range

Something went wrong with that request. Please try again.