Skip to content

Commit

Permalink
WorkflowActionForm: run service as a background job
Browse files Browse the repository at this point in the history
  • Loading branch information
dunn committed Nov 13, 2023
1 parent a96e0e4 commit 7e922e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/forms/hyrax/forms/workflow_action_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ def initialize(current_ability:, work:, attributes: {})

def save
return false unless valid?
Workflow::WorkflowActionService.run(subject: subject,
action: sipity_workflow_action,
comment: comment)

WorkflowActionJob.perform_later(
comment: comment,
name: name,
user: current_user,
work_id: work.id.to_s,
workflow: subject.entity.workflow
)

true
end

Expand Down
14 changes: 14 additions & 0 deletions app/jobs/workflow_action_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
class WorkflowActionJob < Hyrax::ApplicationJob
def perform(comment: nil, name: false, user:, work_id:, workflow:)
work = Hyrax.query_service.find_by(id: work_id)
subject = ::Hyrax::WorkflowActionInfo.new(work, user)
action = Sipity::WorkflowAction(name, workflow)

::Hyrax::Workflow::WorkflowActionService.run(
subject: subject,
action: action,
comment: comment
)
end
end

0 comments on commit 7e922e6

Please sign in to comment.