Hi, There I need help with discours plugin development

In my plugin, I need something like, Whenever a Ajax request is sent to “/admin/plugins/delete_all_posts” I want to schedule a cron job on the server that runs every two minutes until the task is finished. Below is the code and commented lines that are just I tried but giving me an error when I send an Ajax request.

I have written code for a job in
=> lib\jobs\scheduled\delete_user_posts_job.rb
also tried moving it to
=> app\jobs\scheduled\delete_user_posts_job.rb

get '/admin/plugins/delete_all_posts' => proc { |_env|
 uname = SiteSetting.delete_posts_for_username
    userobj = User.find_by(username: uname)
#require_dependency File.expand_path("../app/jobs/scheduled/delete_user_posts_job.rb", __FILE__) 

        # Require the job file to load the job class

        # require_dependency Rails.root.join('plugins', 'delete-topic-ui', 'app', 'jobs', 'scheduled', 'delete_user_posts_job')
        # Start the cron job to delete posts for the specified user



        # Jobs::Scheduled::DeleteAllPosts.enqueue
        [200, {}, ['Cron job for deleting user posts has been scheduled']]