-2

I have a rails service that process some job. I want to send logs to view so user knows the current state of the process.

The view will have status indicator and log container.

Here's a sample view

Status: Running

**LOGS**
2017-02-27 10:00:00 - Job started..
2017-02-27 10:00:10 - Downloading some_file from server..
2017-02-27 10:00:40 - Download successfull..
2017-02-27 10:01:20 - Compressing file..
2017-02-27 10:01:52 - Sending file..
2017-02-27 10:02:02 - Job ended.
Jurot King
  • 79
  • 7

1 Answers1

0

The idea is background job will write log to temporary table. A javascript interval process will be performed at View in order to call to sever every 5 seconds to get new log records. Let's see example:

$(document).ready(function () {
    setInterval(refreshPartial, 5000)
  });
  function refreshPartial() {
    $.ajax({
      url: "#{'/writing_log/refresh_detai?filter_by=%s' % [params[:filter_by]]}"
    })
  }
Will Nguyen
  • 339
  • 1
  • 10