I have a method like so:
def self.perform
total_done = 0
all_user_roles = UserRole.all
user_roles_count = all_user_roles.count
Rails.logger.info "Going to loop #{user_roles_count} times"
all_user_roles.each do |user_role|
Rails.logger.info "starting the loop..."
if user_role.invalid?
Rails.logger.info "Skipping, role invalid."
next
end
role_name = RoleService.send(
:role_name,
role: user_role[:role],
project: user_role.project
)
existing_role = RoleService.get_for_user(user_role.user, project: user_role.project)
if existing_role.present?
Rails.logger.info "Skipping role because it already exists."
next
end
RoleService.set_for_user(
user_role.user,
project: user_role.project
)
migrated_roles += 1
end
Rails.logger.info "DONE"
rescue StandardError => e
Rails.logger.error("Error!")
end
To my surprise, I see it should loop 1000 times:
>>> Going to loop 1000 times
...but neither the DONE message nor the Error at the end are logged. I see it runs 105 times, and then no more messages in the log.
What could be happening here? Is there a way for something to be raised from one of those service calls and not be caught by the general rescue at the end?
I'm running out of ideas...
Thanks!