4tolexx

custom task batch actions

Oct 23rd, 2025
983
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.77 KB | None | 1 0
  1.     def add_custom_task_batch_actions
  2.       batch_action(
  3.         :execute_custom_task,
  4.         form: -> {
  5.           tasks = CustomTask.where("? = ANY(input_record_types)", resource_class.name)
  6.           {
  7.             custom_task_id: tasks.map { |t| [t.name, t.id] }
  8.           }
  9.         }) do |ids, inputs|
  10.         custom_task = CustomTask.find(inputs[:custom_task_id])
  11.         background_job = CustomTaskWorker.perform_async(
  12.           custom_task.id,
  13.           resource_class.name,
  14.           ids,
  15.           name: custom_task.name,
  16.           custom_task_id: custom_task.id
  17.         )
  18.  
  19.         redirect_to(
  20.           admin_background_job_path(background_job),
  21.           notice: "Your custom task is being executed in the background."
  22.         )
  23.       end
  24.     end
  25.  
Advertisement
Add Comment
Please, Sign In to add comment