class ExportJob < ProgressJob::Base
def perform
update_stage('Import')
@users.each do |user|
#обработка данных
update_progress
end
end
def import_from_csv
@job = Delayed::Job.enqueue ExportJob.new(users)
end
<div class="well">
<div class="row">
<div class="col-xs-12">
<div class="progress-status text-primary">
0/0
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="progress progress-striped active">
<div class="progress-bar">
<div class="text-primary">
0%
</div>
</div>
</div>
</div>
</div>
</div>
:plain
var interval;
interval = setInterval(function(){
$.ajax({
url: '/progress-job/' + #{@job.id},
success: function(job){
var stage, progress;
// If there are errors
if (job.last_error != null) {
$('.progress-status').addClass('text-danger').text(job.progress_stage);
$('.progress-bar').addClass('progress-bar-danger');
$('.progress').removeClass('active');
clearInterval(interval);
}
progress = job.progress_current / job.progress_max * 100;
progress = progress.toFixed(2)
// In job stage
if (progress.toString() !== 'NaN'){
$('.progress-status').text(job.progress_current + '/' + job.progress_max);
$('.progress-bar').css('width', progress + '%').text(progress + '%');
}
},
error: function(){
// Job is no loger in database which means it finished successfuly
$('.progress').removeClass('active');
$('.progress-bar').css('width', '100%').text('100%');
$('.progress-status').text('Successfully exported!');
$('.export-link').show();
clearInterval(interval);
}
})
},100);
get 'import' => 'csv#import_from_csv'