Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function initJobStatusPoller(options) {
- // $(document).ready(function() {
- // var jobId = options.jobId;
- // var statusContainer = $('#job_status_container_' + jobId);
- // var currentStatus = options.currentStatus;
- // if (!statusContainer.length ||
- // !['working', 'queued', 'retrying'].includes(currentStatus) ||
- // statusContainer.data('polling') === true) {
- // return;
- // }
- // statusContainer.data('polling', true);
- // console.log('Job status poller initialized for job', jobId, 'with status', currentStatus);
- // var intervalId = setInterval(function() {
- // if (!$.contains(document.documentElement, statusContainer[0])) {
- // clearInterval(intervalId);
- // return;
- // }
- // $.ajax({
- // url: '/admin/background_jobs/' + jobId + '/job_status',
- // type: 'GET',
- // success: function(data) {
- // statusContainer.html(data);
- // var newStatus;
- // var tempDiv = $('<div>').html(data);
- // var statusTag = tempDiv.find('.job-status .status_tag');
- // if (statusTag.length) {
- // var statusText = statusTag.text().trim().toLowerCase();
- // if (statusText === 'successful') newStatus = 'complete';
- // else if (statusText === 'failed') newStatus = 'failed';
- // else if (statusText === 'cancelled') newStatus = 'stopped';
- // else if (statusText === 'running') newStatus = 'working';
- // else if (statusText === 'retrying') newStatus = 'retrying';
- // else newStatus = statusText;
- // console.log('Detected status:', newStatus);
- // }
- // if (['complete', 'failed', 'stopped', 'successful'].includes(newStatus)) {
- // clearInterval(intervalId);
- // console.log('Job ' + jobId + ' is now ' + newStatus + ', stopping polling and refreshing page');
- // setTimeout(function() {
- // window.location.href = window.location.href;
- // }, 1000);
- // }
- // },
- // error: function(xhr, status, error) {
- // console.error('Error fetching job status for job ' + jobId + ':', error);
- // clearInterval(intervalId);
- // }
- // });
- // }, 5000);
- // statusContainer.data('intervalId', intervalId);
- // });
- // }
- // window.initJobStatusPoller = initJobStatusPoller;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement