From 5d9d46aec1bf4a6b77ccea635eaa089a5f271b88 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 30 Jul 2013 17:28:26 +0100 Subject: Add a rake task to print a warning if the state of a submodule is not what we expect it to be. --- lib/tasks/submodules.rake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/tasks/submodules.rake (limited to 'lib/tasks') diff --git a/lib/tasks/submodules.rake b/lib/tasks/submodules.rake new file mode 100644 index 000000000..6da0ff4b8 --- /dev/null +++ b/lib/tasks/submodules.rake @@ -0,0 +1,27 @@ + +namespace :submodules do + + desc "Check the status of the project's submodules" + task :check => :environment do + commit_info = `git submodule status` + sha, repo, branch = commit_info.split(' ') + case sha[0] + when '+' + $stderr.puts "Warning: Currently checked out submodule commit for #{repo}" + $stderr.puts "does not match the commit expected by this version of Alaveteli." + $stderr.puts "You can update it with 'git submodule update'." + exit(1) + when '-' + $stderr.puts "Warning: Submodule #{repo} needs to be initialized." + $stderr.puts "You can do this by running 'git submodule update --init'." + exit(1) + when 'U' + $stderr.puts "Warning: Submodule #{repo} has merge conflicts." + $stderr.puts "You'll probably need to resolve these to run Alaveteli." + exit(1) + else + exit(0) + end + end + +end -- cgit v1.2.3 From 8d49b6838f7dfc2e72808752735cc6ee224ffcb0 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 30 Jul 2013 18:03:31 +0100 Subject: Get first character in a way that will work in Ruby 1.8 and 1.9 --- lib/tasks/submodules.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/tasks') diff --git a/lib/tasks/submodules.rake b/lib/tasks/submodules.rake index 6da0ff4b8..4d414ea84 100644 --- a/lib/tasks/submodules.rake +++ b/lib/tasks/submodules.rake @@ -5,7 +5,7 @@ namespace :submodules do task :check => :environment do commit_info = `git submodule status` sha, repo, branch = commit_info.split(' ') - case sha[0] + case sha[0,1] when '+' $stderr.puts "Warning: Currently checked out submodule commit for #{repo}" $stderr.puts "does not match the commit expected by this version of Alaveteli." -- cgit v1.2.3 From 7caa577e504fb3212c833eb23dc0f1ed6dae464c Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 30 Jul 2013 18:23:31 +0100 Subject: Call it an error, not a warning. --- lib/tasks/submodules.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/tasks') diff --git a/lib/tasks/submodules.rake b/lib/tasks/submodules.rake index 4d414ea84..1112e443e 100644 --- a/lib/tasks/submodules.rake +++ b/lib/tasks/submodules.rake @@ -7,17 +7,17 @@ namespace :submodules do sha, repo, branch = commit_info.split(' ') case sha[0,1] when '+' - $stderr.puts "Warning: Currently checked out submodule commit for #{repo}" + $stderr.puts "Error: Currently checked out submodule commit for #{repo}" $stderr.puts "does not match the commit expected by this version of Alaveteli." $stderr.puts "You can update it with 'git submodule update'." exit(1) when '-' - $stderr.puts "Warning: Submodule #{repo} needs to be initialized." + $stderr.puts "Error: Submodule #{repo} needs to be initialized." $stderr.puts "You can do this by running 'git submodule update --init'." exit(1) when 'U' - $stderr.puts "Warning: Submodule #{repo} has merge conflicts." - $stderr.puts "You'll probably need to resolve these to run Alaveteli." + $stderr.puts "Error: Submodule #{repo} has merge conflicts." + $stderr.puts "You'll need to resolve these to run Alaveteli." exit(1) else exit(0) -- cgit v1.2.3 From 9f62a26384232890d8dcdc56cd5983b793db3be1 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 8 Aug 2013 15:13:13 +0100 Subject: Only check commonlib, don't try to split the response into segments (as @mhl points out, the case where the initial character is a space is somewhat confusing), just grab the first character of the whole string and check it against expected values. --- lib/tasks/submodules.rake | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/tasks') diff --git a/lib/tasks/submodules.rake b/lib/tasks/submodules.rake index 1112e443e..426192713 100644 --- a/lib/tasks/submodules.rake +++ b/lib/tasks/submodules.rake @@ -3,24 +3,25 @@ namespace :submodules do desc "Check the status of the project's submodules" task :check => :environment do - commit_info = `git submodule status` - sha, repo, branch = commit_info.split(' ') - case sha[0,1] + commit_info = `git submodule status commonlib` + case commit_info[0,1] when '+' - $stderr.puts "Error: Currently checked out submodule commit for #{repo}" + $stderr.puts "Error: Currently checked out submodule commit for commonlib" $stderr.puts "does not match the commit expected by this version of Alaveteli." $stderr.puts "You can update it with 'git submodule update'." exit(1) when '-' - $stderr.puts "Error: Submodule #{repo} needs to be initialized." + $stderr.puts "Error: Submodule commonlib needs to be initialized." $stderr.puts "You can do this by running 'git submodule update --init'." exit(1) when 'U' - $stderr.puts "Error: Submodule #{repo} has merge conflicts." + $stderr.puts "Error: Submodule commonlib has merge conflicts." $stderr.puts "You'll need to resolve these to run Alaveteli." exit(1) - else + when ' ' exit(0) + else + raise "Unexpected status character in response to 'git submodule status commonlib': #{commit_info[0,1]}" end end -- cgit v1.2.3 From bb891af57ba2cafa792a2ecb622975f19bd69ed9 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 7 Aug 2013 17:47:29 +0100 Subject: Add task for cleaning up bad request histories. --- lib/tasks/temp.rake | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/tasks') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index fcabb23de..5dba4fb7a 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -1,5 +1,35 @@ namespace :temp do + desc "Fix the history of requests where the described state doesn't match the latest status value + used by search, by adding an edit event that will correct the latest status" + task :fix_bad_request_states => :environment do + dryrun = ENV['DRYRUN'] != '0' + if dryrun + puts "This is a dryrun" + end + + InfoRequest.find_each() do |info_request| + next if info_request.url_title == 'holding_pen' + last_info_request_event = info_request.info_request_events[-1] + if last_info_request_event.latest_status != info_request.described_state + puts "#{info_request.id} #{info_request.url_title} #{last_info_request_event.latest_status} #{info_request.described_state}" + params = { :script => 'rake temp:fix_bad_request_states', + :user_id => nil, + :old_described_state => info_request.described_state, + :described_state => info_request.described_state + } + if ! dryrun + info_request.info_request_events.create!(:last_described_at => last_info_request_event.described_at + 1.second, + :event_type => 'status_update', + :described_state => info_request.described_state, + :calculated_state => info_request.described_state, + :params => params) + end + end + + end + end + def disable_duplicate_account(user, count, dryrun) dupe_email = "duplicateemail#{count}@example.com" puts "Updating #{user.email} to #{dupe_email} for user #{user.id}" -- cgit v1.2.3 From dfb5f97ac44656f0e021b09856e0c54b9fa41b3f Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 20 Aug 2013 15:43:59 +0100 Subject: Mark all events for the fixed requests as needing a reindex. --- lib/tasks/temp.rake | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'lib/tasks') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index 5dba4fb7a..f746338f0 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -24,6 +24,7 @@ namespace :temp do :described_state => info_request.described_state, :calculated_state => info_request.described_state, :params => params) + info_request.info_request_events.each{ |event| event.mark_needs_xapian_index } end end @@ -43,15 +44,21 @@ namespace :temp do total_messages = 0 messages_to_reparse = 0 IncomingMessage.find_each :include => :foi_attachments do |im| - reparse = im.foi_attachments.any? { |fa| ! File.exists? fa.filepath } - total_messages += 1 - messages_to_reparse += 1 if reparse - if total_messages % 1000 == 0 - puts "Considered #{total_messages} received emails." - end - unless dry_run - im.parse_raw_email! true if reparse - sleep 2 + begin + reparse = im.foi_attachments.any? { |fa| ! File.exists? fa.filepath } + total_messages += 1 + messages_to_reparse += 1 if reparse + if total_messages % 1000 == 0 + puts "Considered #{total_messages} received emails." + end + unless dry_run + im.parse_raw_email! true if reparse + sleep 2 + end + rescue StandardError => e + puts "There was a #{e.class} exception reparsing IncomingMessage with ID #{im.id}" + puts e.backtrace + puts e.message end end message = dry_run ? "Would reparse" : "Reparsed" -- cgit v1.2.3