Skip to content

Commit

Permalink
feed updater: do not fetch feeds for archived canteens
Browse files Browse the repository at this point in the history
  • Loading branch information
mswart committed Jul 2, 2015
1 parent 213ad9b commit fd9d48e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/open_mensa/update_feeds_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ def do
end

def fix_next_fetch_ats
changes = Feed.where { (schedule == nil) & (next_fetch_at != nil) }.update_all(next_fetch_at: nil)
Feed.where { (schedule != nil) & (next_fetch_at == nil) }.each do |feed|
disabled_feeds = Feed.joins { source.canteen }.where { source.canteen.state == 'archived' }.select(:id)
changes = Feed.where { ((schedule == nil) | id.in(disabled_feeds)) & (next_fetch_at != nil) }.update_all(next_fetch_at: nil)
Feed.where { (schedule != nil) & id.not_in(disabled_feeds) & (next_fetch_at == nil) }.each do |feed|
feed.next_fetch_at = CronParser.new(feed.schedule).last
feed.save!
changes += 1
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/open_mensa/update_feeds_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,16 @@ def new_feed(attrs={})

task.do
end

it 'should only fetch active feeds/sources' do
feed = new_feed schedule: '*/15 8-9 * * *', next_fetch_at: _815
feed3 = new_feed schedule: '0 8-9 * * *', next_fetch_at: _834
feed3.canteen.update_attributes state: 'archived'

expect(OpenMensa::Updater).to receive(:new).with(feed, 'schedule').ordered.and_return(success_updater)
expect(OpenMensa::Updater).to_not receive(:new)

task.do
end
end
end

0 comments on commit fd9d48e

Please sign in to comment.