def add_custom_task_batch_actions
batch_action(
:execute_custom_task,
form: -> {
tasks = CustomTask.where("? = ANY(input_record_types)", resource_class.name)
{
custom_task_id: tasks.map { |t| [t.name, t.id] }
}
}) do |ids, inputs|
custom_task = CustomTask.find(inputs[:custom_task_id])
background_job = CustomTaskWorker.perform_async(
custom_task.id,
resource_class.name,
ids,
name: custom_task.name,
custom_task_id: custom_task.id
)
redirect_to(
admin_background_job_path(background_job),
notice: "Your custom task is being executed in the background."
)
end
end