Delay a function, any function!

You could solve this via WP Cron using wp_schedule_single_event(). However, for this to properly work, you’d need to disable the standard cron (which is run by a user visiting the site) and instead use a proper cronjob/crontab. EasyEngine has a good tutorial on disabling wp-cron and using cronjob instead.

An alternative would be solve this via an AJAX request. You could invoke the function via JS on the thank you page. The docu explains how to do this, in simple terms it could look like this

<script>
jQuery.post(
    ajaxurl, 
    {
        'action': 'do_my_long_action',
        'data':   'some_data'
    }, 
    function(response){
        //
    }
);
</script>

and

add_action( 'wp_ajax_do_my_long_action', 'prefix_ajax_add_foobar' );
function prefix_ajax_add_foobar() {
    // handle request

    // sent success message (or wp_die())
    wp_send_json(

    );
}