How should Sidekiq notify user on the web page when job is finished?
Add a RecordJobs
model to your application that stores who uploaded the records, the number of records, the upload time and so on.
Create a new record_job
each time someone uploads new records and pass its id
to the worker. The worker can update that instance to indicate its progress.
At the same time, the application can query for existing record_job
and show their progress. That can be done whenever the user reloads it page, by active polling or with web sockets (depending on your needs).
use ActionCable, here is the example with Report channel
In routes.rb add the following line
mount ActionCable.server => '/cable'
create a ReportChannel.rb inside app/channels with following code
class ReportChannel < ApplicationCable::Channel
def subscribed
stream_from "report_#{current_user.id}"
end
end
create reports.coffee inside app/assets/javascripts/channels with the following code
window.App.Channels ||= {}
window.App.Channels.Report ||= {}
window.App.Channels.Report.subscribe = ->
App.report = App.cable.subscriptions.create "ReportChannel",
connected: ->
console.log('connected ')
disconnected: ->
console.log('diconnected ')
received: (data) ->
console.log('returned ')
data = $.parseJSON(data)
#write your code here to update or notify user#
and add the following lines at the end of your job
ActionCable.server.broadcast("*report_*#{current_user_id}", data_in_json_format)
replace report with your specific model
seems simple right :)