Class: Hyrax::Actors::FileActor

Inherits:
Object
  • Object
show all
Defined in:
app/actors/hyrax/actors/file_actor.rb

Overview

Note:

Spawns asynchronous jobs

Actions for a file identified by file_set and relation (maps to use predicate)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set, relation, user) ⇒ FileActor

Returns a new instance of FileActor.

Parameters:

  • file_set (FileSet)

    the parent FileSet

  • relation (Symbol, #to_sym)

    the type/use for the file

  • user (User)

    the user to record as the Agent acting upon the file



11
12
13
14
15
# File 'app/actors/hyrax/actors/file_actor.rb', line 11

def initialize(file_set, relation, user)
  @file_set = file_set
  @relation = relation.to_sym
  @user = user
end

Instance Attribute Details

#file_setObject (readonly)

Returns the value of attribute file_set.



6
7
8
# File 'app/actors/hyrax/actors/file_actor.rb', line 6

def file_set
  @file_set
end

#relationObject (readonly)

Returns the value of attribute relation.



6
7
8
# File 'app/actors/hyrax/actors/file_actor.rb', line 6

def relation
  @relation
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'app/actors/hyrax/actors/file_actor.rb', line 6

def user
  @user
end

Instance Method Details

#==(other) ⇒ Object

Note:

FileSet comparison is limited to IDs, but this should be sufficient, given that most operations here are on the other side of async retrieval in Jobs (based solely on ID).



49
50
51
52
# File 'app/actors/hyrax/actors/file_actor.rb', line 49

def ==(other)
  return false unless other.is_a?(self.class)
  file_set.id == other.file_set.id && relation == other.relation && user == other.user
end

#ingest_file(io) ⇒ CharacterizeJob, FalseClass

TODO:

create a job to monitor the temp directory (or in a multi-worker system, directories!) to prune old files that have made it into the repo

Note:

Instead of calling this method, use IngestJob to avoid synchronous execution cost

Persists file as part of file_set and spawns async job to characterize and create derivatives.

Parameters:

  • io (JobIoWrapper)

    the file to save in the repository, with mime_type and original_name

Returns:

  • (CharacterizeJob, FalseClass)

    spawned job on success, false on failure

See Also:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/actors/hyrax/actors/file_actor.rb', line 23

def ingest_file(io)
  # Skip versioning because versions will be minted by VersionCommitter as necessary during save_characterize_and_record_committer.
  Hydra::Works::AddFileToFileSet.call(file_set,
                                      io,
                                      relation,
                                      versioning: false)
  return false unless file_set.save
  repository_file = related_file
  Hyrax::VersioningService.create(repository_file, user)
  pathhint = io.uploaded_file.uploader.path if io.uploaded_file # in case next worker is on same filesystem
  CharacterizeJob.perform_later(file_set, repository_file.id, pathhint || io.path)
end

#revert_to(revision_id) ⇒ CharacterizeJob, FalseClass

Reverts file and spawns async job to characterize and create derivatives.

Parameters:

  • revision_id (String)

Returns:

  • (CharacterizeJob, FalseClass)

    spawned job on success, false on failure



39
40
41
42
43
44
45
# File 'app/actors/hyrax/actors/file_actor.rb', line 39

def revert_to(revision_id)
  repository_file = related_file
  repository_file.restore_version(revision_id)
  return false unless file_set.save
  Hyrax::VersioningService.create(repository_file, user)
  CharacterizeJob.perform_later(file_set, repository_file.id)
end