Sha256: 15efdd0380c014f70322c19f99dc413cbb6821a64f52fe3ec42eafe888b7fd72

Contents?: true

Size: 1.14 KB

Versions: 19

Compression:

Stored size: 1.14 KB

Contents

class IngestLocalFileJob
  attr_accessor :directory, :filename, :user_key, :generic_file_id

  def queue_name
    :ingest
  end

  def initialize(generic_file_id, directory, filename, user_key)
    self.generic_file_id = generic_file_id
    self.directory = directory
    self.filename = filename
    self.user_key = user_key
  end

  def run
    user = User.find_by_user_key(user_key)
    raise "Unable to find user for #{user_key}" unless user
    generic_file = GenericFile.find(generic_file_id)
    path = File.join(directory, filename)

    generic_file.label = File.basename(filename)
    generic_file.add_file(File.open(path), 'content', generic_file.label)
    generic_file.record_version_committer(user)
    generic_file.save!

    FileUtils.rm(path)
    Sufia.queue.push(ContentDepositEventJob.new(generic_file.pid, user_key))
    # add message to user for downloaded file
    message = "The file (#{File.basename(filename)}) was successfully deposited."
    job_user.send_message(user, message, 'Local file ingest')
  rescue => error
    job_user.send_message(user, error.message, 'Local file ingest error')
  end

  def job_user
    User.batchuser
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
sufia-5.0.0 app/jobs/ingest_local_file_job.rb
sufia-5.0.0.rc1 app/jobs/ingest_local_file_job.rb
sufia-4.3.1 app/jobs/ingest_local_file_job.rb
sufia-4.2.0 app/jobs/ingest_local_file_job.rb
sufia-4.1.0 app/jobs/ingest_local_file_job.rb
sufia-4.0.1 app/jobs/ingest_local_file_job.rb
sufia-4.0.0 app/jobs/ingest_local_file_job.rb
sufia-4.0.0.rc2 app/jobs/ingest_local_file_job.rb
sufia-4.0.0.rc1 app/jobs/ingest_local_file_job.rb
sufia-4.0.0.beta4 app/jobs/ingest_local_file_job.rb
sufia-4.0.0.beta3 app/jobs/ingest_local_file_job.rb
sufia-4.0.0.beta2 app/jobs/ingest_local_file_job.rb
sufia-4.0.0.beta1 app/jobs/ingest_local_file_job.rb
sufia-3.7.2 app/jobs/ingest_local_file_job.rb
sufia-3.7.1 app/jobs/ingest_local_file_job.rb
sufia-3.7.0 app/jobs/ingest_local_file_job.rb
sufia-3.6.1 app/jobs/ingest_local_file_job.rb
sufia-3.6.0 app/jobs/ingest_local_file_job.rb
sufia-3.5.0 app/jobs/ingest_local_file_job.rb