Class: BulkOps::WorkJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/bulk_ops/work_job.rb

Overview

require ‘hydra/access_controls’ require ‘hyrax/workflow/activate_object’

Direct Known Subclasses

CreateWorkJob, UpdateWorkJob

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/bulk_ops/work_job.rb', line 5

def status
  @status
end

#type=(value) ⇒ Object

Sets the attribute type

Parameters:

  • value

    the value to set the attribute type to.



5
6
7
# File 'lib/bulk_ops/work_job.rb', line 5

def type=(value)
  @type = value
end

#workObject

Returns the value of attribute work.



5
6
7
# File 'lib/bulk_ops/work_job.rb', line 5

def work
  @work
end

Instance Method Details

#perform(workClass, user_email, attributes, work_proxy_id, visibility = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bulk_ops/work_job.rb', line 45

def perform(workClass,user_email,attributes,work_proxy_id,visibility=nil)
  return if status == "complete"
  update_status "starting", "Initializing the job"
  attributes['visibility']= visibility if visibility.present?
  attributes['title'] = ['Untitled'] if attributes['title'].blank?
  @work_proxy = BulkOps::WorkProxy.find(work_proxy_id)
  unless @work_proxy
    report_error("Cannot find work proxy with id: #{work_proxy_id}") 
    return
  end

  return unless (work_action = define_work(workClass))

  user = User.find_by_email(user_email)
  update_status "running", "Started background task at #{DateTime.now.strftime("%d/%m/%Y %H:%M")}"
  ability = Ability.new(user)
  env = Hyrax::Actors::Environment.new(@work, ability, attributes)
  update_status "complete", Hyrax::CurationConcern.actor.send(work_action,env)
end