2020-01-28 04:09:06 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-19 13:09:10 -05:00
|
|
|
class GroupImportWorker # rubocop:disable Scalability/IdempotentWorker
|
2020-01-28 04:09:06 -05:00
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-07-21 08:09:35 -04:00
|
|
|
data_consistency :always
|
|
|
|
|
2020-10-15 23:08:29 -04:00
|
|
|
sidekiq_options retry: false, dead: false
|
2020-01-28 04:09:06 -05:00
|
|
|
feature_category :importers
|
|
|
|
|
|
|
|
def perform(user_id, group_id)
|
|
|
|
current_user = User.find(user_id)
|
|
|
|
group = Group.find(group_id)
|
2020-09-21 14:09:58 -04:00
|
|
|
group_import_state = group.import_state
|
2020-04-25 11:09:53 -04:00
|
|
|
|
2020-06-14 20:08:43 -04:00
|
|
|
group_import_state.jid = self.jid
|
|
|
|
group_import_state.start!
|
2020-01-28 04:09:06 -05:00
|
|
|
|
|
|
|
::Groups::ImportExport::ImportService.new(group: group, user: current_user).execute
|
2020-04-25 11:09:53 -04:00
|
|
|
|
2020-06-14 20:08:43 -04:00
|
|
|
group_import_state.finish!
|
2020-04-25 11:09:53 -04:00
|
|
|
rescue StandardError => e
|
2020-06-14 20:08:43 -04:00
|
|
|
group_import_state&.fail_op(e.message)
|
2020-04-25 11:09:53 -04:00
|
|
|
|
|
|
|
raise e
|
2020-01-28 04:09:06 -05:00
|
|
|
end
|
|
|
|
end
|