Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:53:53+00:00 2026-06-14T10:53:53+00:00

Lets say I have a blog application with posts. After creating a post a

  • 0

Lets say I have a blog application with posts. After creating a post a worker is created to handle some background operations. My case is that after submitting a post form I want to display some kind of loading message (gif loader or such) and when the worker finishes I want to hide the loading message and display some data supplied by the worker. My question is what’s the best way to communicate that a worker has finished its job and display it on the frontend for user. Worker callback looks something like this

def worker_finish
  #message the user
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:53:54+00:00Added an answer on June 14, 2026 at 10:53 am

    I think you may be missing the point of having background workers, basically, what you’re attempting to do is self defeating. — If the user submits the form and you queue the job in your controller, only to make the user wait for the worker to both start and finish, you not only accomplished exactly what the controller could have done by itself, but you’ve made the process far more complicated (and this type of functionality is not built in to either resque, or sidekiq).

    When offloading a job to be processed by a queue you want to return a response to the client immediately, i.e.

    class PostsController < ApplicationController
      def create
        @post = Post.create(params[:post])
        BackgroundBlogOperation.enque(@post.id)
        respond_with(@post)
      end
    end
    

    The BackgroundBlogOperation class would then be placed into a queue, for a worker to go through and work off. If you need the BackgroundBlogOperation worker to do something else after it’s finished, you can do so, but that should take place within the job itself, so that the worker can be responsible for that.

    If you are just trying to display and hide the spinner after a post is created, without page reloading, just display the javascript spinner before click of the submit button, and make sure the request type is js (add :remote => true to form). Then create a javascript view response that looks like:

    class PostsController < ApplicationController
      respond_to :js, :only => [:create]
      def create
        @post = Post.create(params[:post])
        BackgroundBlogOperation.enque(@post.id)
        respond_with(@post)
      end
    end
    

    And the create.js.erb, could also append a message telling them that whatever you are doing in the background has been queued, if its more complex than creating a post or whatever.

    $("#spinner").hide();
    

    Now — Although what you were asking originally doesent serve any purpose (because to display and hide the spinner on completion of the job would require waiting for the controller to complete the action) — There are situations where displaying to the client that the job has finished processing is useful.

    First lets define a scenario where background processing is actually useful. Lets say you have a button that when click, will pull in data from some external api, and after getting data from the external site, you are performing a database operation based on the response. This would be a good example of when to use background process. Basically in the controller you would do something like:

    class ApiController < ApplicationController
      respond_to :js, :only => [:create]
    
      def sync_tweets
        TwitterApiJob.enque(current_user.twitter_username)
        respond_with(message: 'Syncing Tweets')
      end
    
    end
    

    Now, to tell the user when the tweets have finished syncing is a bit more complicated, and you have 3 basic options:

    1) Notify user via email (generally worst option imo)
    2) Use some sort of html5 or websocket capable rails server to run rails, and send a push through the websocket to the client, which although very cool, is in most cases overkill and outside the scope of this response. Google rails websocket pushing if you want to see your options.
    3) IMO best option for most cases, Create a notifcations model to handle all sorts of user notifications, and in your job, after the work is complete, do something like

    Notification.create(:user_id => user.id, :message => 'Sync has finished', type => 'sync_complete')
    

    Then, next page the user requests, up in a header toolbar or wherever, I would have a notice that the user has unread notifications, to alert the user to click on it.

    — Also I think in your post you mentioned you are using resque. I tried resque and it was decent, but I found it overcomplicated to debug in production, and it used crazy memory — I would advise you to check out sidekiq if you haven’t already, it uses redis also but much faster as it uses threads:

    https://github.com/mperham/sidekiq

    It is much faster, cleaner, and easy to get setup, imho.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i have a blog with 10 posts. I want to display 20
Lets say I have 2 tables: blog_posts and categories. Each blog post belongs to
For intance, lets say we have 50 posts in a blog. With php you
Let's say I have a blog application. On each Post there are Comments. So,
Lets say you have a two models with blog posts and comments set up
I have a blog which i get about 1200 visits a month lets say
Lets say I have multiple commands like 5000 which updates some column and row
I have a string, lets say: <lic><ic>This is a string</ic>, welcome to my blog.</lic>
I have .NET 3.5 web application which uses some COM dll created in VB6.
Let's say I have a simple ASP.NET MVC blog application and I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.