Minor fixes to `Jobs::BulkInvite`.
This commit is contained in:
parent
092fb0c170
commit
4f81d4cc8e
|
@ -8,6 +8,7 @@ module Jobs
|
|||
attr_accessor :current_user
|
||||
|
||||
def initialize
|
||||
super
|
||||
@logs = []
|
||||
@sent = 0
|
||||
@failed = 0
|
||||
|
@ -38,13 +39,13 @@ module Jobs
|
|||
@sent += 1
|
||||
else
|
||||
# invalid email
|
||||
log "Invalid Email '#{csv_info[0]}' at line number '#{$INPUT_LINE_NUMBER}'"
|
||||
save_log "Invalid Email '#{csv_info[0]}' at line number '#{$INPUT_LINE_NUMBER}'"
|
||||
@failed += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
log "Bulk Invite Process Failed -- '#{e.message}'"
|
||||
save_log "Bulk Invite Process Failed -- '#{e.message}'"
|
||||
@failed += 1
|
||||
ensure
|
||||
file.close
|
||||
|
@ -61,7 +62,7 @@ module Jobs
|
|||
group_ids.push(group_detail.id)
|
||||
else
|
||||
# invalid group
|
||||
log "Invalid Group '#{group_name}' at line number '#{csv_line_number}'"
|
||||
save_log "Invalid Group '#{group_name}' at line number '#{csv_line_number}'"
|
||||
@failed += 1
|
||||
end
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ module Jobs
|
|||
if topic_id
|
||||
topic = Topic.find_by_id(topic_id)
|
||||
if topic.nil?
|
||||
log "Invalid Topic ID '#{topic_id}' at line number '#{csv_line_number}'"
|
||||
save_log "Invalid Topic ID '#{topic_id}' at line number '#{csv_line_number}'"
|
||||
@failed += 1
|
||||
end
|
||||
end
|
||||
|
@ -88,16 +89,12 @@ module Jobs
|
|||
begin
|
||||
Invite.invite_by_email(email, @current_user, topic, group_ids)
|
||||
rescue => e
|
||||
log "Error inviting '#{email}' -- #{Rails::Html::FullSanitizer.new.sanitize(e.message)}"
|
||||
save_log "Error inviting '#{email}' -- #{Rails::Html::FullSanitizer.new.sanitize(e.message)}"
|
||||
@sent -= 1
|
||||
@failed += 1
|
||||
end
|
||||
end
|
||||
|
||||
def log(message)
|
||||
save_log(message)
|
||||
end
|
||||
|
||||
def save_log(message)
|
||||
@logs << "[#{Time.now}] #{message}"
|
||||
end
|
||||
|
@ -105,9 +102,19 @@ module Jobs
|
|||
def notify_user
|
||||
if @current_user
|
||||
if (@sent > 0 && @failed == 0)
|
||||
SystemMessage.create_from_system_user(@current_user, :bulk_invite_succeeded, sent: @sent)
|
||||
SystemMessage.create_from_system_user(
|
||||
@current_user,
|
||||
:bulk_invite_succeeded,
|
||||
sent: @sent
|
||||
)
|
||||
else
|
||||
SystemMessage.create_from_system_user(@current_user, :bulk_invite_failed, sent: @sent, failed: @failed, logs: @logs.join("\n"))
|
||||
SystemMessage.create_from_system_user(
|
||||
@current_user,
|
||||
:bulk_invite_failed,
|
||||
sent: @sent,
|
||||
failed: @failed,
|
||||
logs: @logs.join("\n")
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue