Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

Using a Controller Method with Resque Background Job

$
0
0

I am on Rails 4 using Resque with Redis.

How can I use a controller method, which is currently defined in my application_controller, inside of my background job?

Here is the current method I have defined:

def push_to_google(token, message)  if token.present?    gcm = GCM.new("843jf9384fj839f848j890fj3")    registration_ids = ["#{token}"] # an array of one or more client registration tokens    options = {data: {notification: "#{message}"}}    response = gcm.send(registration_ids, options)  endend

which I would like to use in this background job defined in my delayed_notifications:

class DelayedNotifications  @queue = :notifications_queue  def self.perform(registration_id, user_name)    push_to_google(registration_id, "New message from #{user_name}.")  endend

Of course, my jobs are currently failing with this error:

undefined method 'push_to_google' for DelayedNotifications:Class


Viewing all articles
Browse latest Browse all 873

Trending Articles