Class: IngestLocalFileJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/ingest_local_file_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



2
3
4
# File 'app/jobs/ingest_local_file_job.rb', line 2

def directory
  @directory
end

#file_set_idObject

Returns the value of attribute file_set_id.



2
3
4
# File 'app/jobs/ingest_local_file_job.rb', line 2

def file_set_id
  @file_set_id
end

#filenameObject

Returns the value of attribute filename.



2
3
4
# File 'app/jobs/ingest_local_file_job.rb', line 2

def filename
  @filename
end

#user_keyObject

Returns the value of attribute user_key.



2
3
4
# File 'app/jobs/ingest_local_file_job.rb', line 2

def user_key
  @user_key
end

Instance Method Details

#perform(file_set_id, directory, filename, user_key) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/jobs/ingest_local_file_job.rb', line 6

def perform(file_set_id, directory, filename, user_key)
  @file_set_id = file_set_id
  @directory = directory
  @filename = filename
  @user_key = user_key

  user = User.find_by_user_key(user_key)
  fail "Unable to find user for #{user_key}" unless user
  file_set = FileSet.find(file_set_id)
  file_set.label ||= filename
  path = File.join(directory, filename)

  actor = CurationConcerns::FileSetActor.new(file_set, user)

  if actor.create_content(File.open(path))
    FileUtils.rm(path)
    CurationConcerns.config.callback.run(:after_import_local_file_success, file_set, user, filename)
  else
    CurationConcerns.config.callback.run(:after_import_local_file_failure, file_set, user, filename)
  end
end