Commit 55729b442f1fea0923834e2be3b9be8efcdbf9e3
Committed by
Antonio Terceiro
1 parent
39e3c25c
Exists in
master
and in
22 other branches
Avoiding some 'delayed job' errors
(ActionItem1740)
Showing
8 changed files
with
58 additions
and
3 deletions
Show diff stats
lib/create_thumbnails_job.rb
1 | class CreateThumbnailsJob < Struct.new(:class_name, :file_id) | 1 | class CreateThumbnailsJob < Struct.new(:class_name, :file_id) |
2 | def perform | 2 | def perform |
3 | + return unless class_name.constantize.exists?(file_id) | ||
3 | Article.disable_ferret # acts_as_ferret sucks | 4 | Article.disable_ferret # acts_as_ferret sucks |
4 | file = class_name.constantize.find(file_id) | 5 | file = class_name.constantize.find(file_id) |
5 | file.create_thumbnails | 6 | file.create_thumbnails |
lib/get_email_contacts_job.rb
@@ -3,9 +3,9 @@ class GetEmailContactsJob < Struct.new(:import_from, :login, :password, :contact | @@ -3,9 +3,9 @@ class GetEmailContactsJob < Struct.new(:import_from, :login, :password, :contact | ||
3 | begin | 3 | begin |
4 | Invitation.get_contacts(import_from, login, password, contact_list_id) | 4 | Invitation.get_contacts(import_from, login, password, contact_list_id) |
5 | rescue Contacts::AuthenticationError => ex | 5 | rescue Contacts::AuthenticationError => ex |
6 | - ContactList.find(contact_list_id).register_auth_error | 6 | + ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).register_auth_error |
7 | rescue Exception => ex | 7 | rescue Exception => ex |
8 | - ContactList.find(contact_list_id).register_error | 8 | + ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).register_error |
9 | end | 9 | end |
10 | end | 10 | end |
11 | end | 11 | end |
lib/invitation_job.rb
@@ -4,7 +4,7 @@ class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :pro | @@ -4,7 +4,7 @@ class InvitationJob < Struct.new(:person_id, :contacts_to_invite, :message, :pro | ||
4 | person = Person.find(person_id) | 4 | person = Person.find(person_id) |
5 | profile = Profile.find(profile_id) | 5 | profile = Profile.find(profile_id) |
6 | Invitation.invite(person, contacts_to_invite, message, profile) | 6 | Invitation.invite(person, contacts_to_invite, message, profile) |
7 | - ContactList.find(contact_list_id).destroy | 7 | + ContactList.exists?(contact_list_id) && ContactList.find(contact_list_id).destroy |
8 | end | 8 | end |
9 | end | 9 | end |
10 | end | 10 | end |
lib/notify_activity_to_profiles_job.rb
@@ -9,6 +9,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | @@ -9,6 +9,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | ||
9 | 'leave_community', | 9 | 'leave_community', |
10 | ] | 10 | ] |
11 | def perform | 11 | def perform |
12 | + return unless ActionTracker::Record.exists?(tracked_action_id) | ||
12 | tracked_action = ActionTracker::Record.find(tracked_action_id) | 13 | tracked_action = ActionTracker::Record.find(tracked_action_id) |
13 | target = tracked_action.target | 14 | target = tracked_action.target |
14 | if target.is_a?(Community) && NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb) | 15 | if target.is_a?(Community) && NOTIFY_ONLY_COMMUNITY.include?(tracked_action.verb) |
test/unit/create_thumbnails_job_test.rb
@@ -24,4 +24,14 @@ class CreateThumbnailsJobTest < ActiveSupport::TestCase | @@ -24,4 +24,14 @@ class CreateThumbnailsJobTest < ActiveSupport::TestCase | ||
24 | assert file.thumbnails_processed | 24 | assert file.thumbnails_processed |
25 | end | 25 | end |
26 | 26 | ||
27 | + should 'not create thumbnails from deleted files' do | ||
28 | + person = create_user('test_user').person | ||
29 | + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => person) | ||
30 | + job = CreateThumbnailsJob.new(file.class.name, file.id) | ||
31 | + file.destroy | ||
32 | + assert_nothing_raised do | ||
33 | + job.perform | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
27 | end | 37 | end |
test/unit/get_email_contacts_job_test.rb
@@ -24,4 +24,24 @@ class GetEmailContactsJobTest < ActiveSupport::TestCase | @@ -24,4 +24,24 @@ class GetEmailContactsJobTest < ActiveSupport::TestCase | ||
24 | assert_equal 'There was an error while authenticating. Did you enter correct login and password?', ContactList.find(contact_list).error_fetching | 24 | assert_equal 'There was an error while authenticating. Did you enter correct login and password?', ContactList.find(contact_list).error_fetching |
25 | end | 25 | end |
26 | 26 | ||
27 | + should 'not try to register error if has no contact list' do | ||
28 | + contact_list = ContactList.create | ||
29 | + Invitation.expects(:get_contacts).with('from-email', 'mylogin', 'mypassword', contact_list.id).raises(Exception.new("crash")) | ||
30 | + job = GetEmailContactsJob.new('from-email', 'mylogin', 'mypassword', contact_list.id) | ||
31 | + contact_list.destroy | ||
32 | + assert_nothing_raised do | ||
33 | + job.perform | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + should 'not try to register auth error if has no contact list' do | ||
38 | + contact_list = ContactList.create | ||
39 | + Invitation.expects(:get_contacts).with('from-email', 'mylogin', 'wrongpassword', contact_list.id).raises(Contacts::AuthenticationError) | ||
40 | + job = GetEmailContactsJob.new('from-email', 'mylogin', 'wrongpassword', contact_list.id) | ||
41 | + contact_list.destroy | ||
42 | + assert_nothing_raised do | ||
43 | + job.perform | ||
44 | + end | ||
45 | + end | ||
46 | + | ||
27 | end | 47 | end |
test/unit/invitation_job_test.rb
@@ -25,4 +25,14 @@ class InvitationJobTest < ActiveSupport::TestCase | @@ -25,4 +25,14 @@ class InvitationJobTest < ActiveSupport::TestCase | ||
25 | job.perform | 25 | job.perform |
26 | end | 26 | end |
27 | 27 | ||
28 | + should 'skip contact list deletion if it not exists' do | ||
29 | + contact_list = ContactList.create! | ||
30 | + person = create_user('maluquete').person | ||
31 | + job = InvitationJob.new(person.id, ['email1@example.com'], 'Hi!', person.id, contact_list.id) | ||
32 | + contact_list.destroy | ||
33 | + assert_nothing_raised do | ||
34 | + job.perform | ||
35 | + end | ||
36 | + end | ||
37 | + | ||
28 | end | 38 | end |
test/unit/notify_activity_to_profiles_job_test.rb
@@ -166,4 +166,17 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase | @@ -166,4 +166,17 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase | ||
166 | assert_equal [], NotifyActivityToProfilesJob::NOT_NOTIFY_COMMUNITY - not_notify_community_verbs | 166 | assert_equal [], NotifyActivityToProfilesJob::NOT_NOTIFY_COMMUNITY - not_notify_community_verbs |
167 | end | 167 | end |
168 | 168 | ||
169 | + should 'cancel notify when target no more exists' do | ||
170 | + person = fast_create(Person) | ||
171 | + friend = fast_create(Person) | ||
172 | + fast_create(Friendship, :person_id => person.id, :friend_id => friend.id) | ||
173 | + action_tracker = fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person.id, :target_type => 'Profile', :verb => 'create_article') | ||
174 | + ActionTrackerNotification.delete_all | ||
175 | + job = NotifyActivityToProfilesJob.new(action_tracker.id) | ||
176 | + person.destroy | ||
177 | + job.perform | ||
178 | + process_delayed_job_queue | ||
179 | + assert_equal 0, ActionTrackerNotification.count | ||
180 | + end | ||
181 | + | ||
169 | end | 182 | end |