lundi 6 avril 2015

Call function from delyed job in rails

I have one function, that have been working in delayed job.



class TestDelay < ActiveRecord::Base
def start_worker
tc = TestController.new

#Here calling that main function
end
end


also i have one other class



class TestController < ApplicationController
before_filter :filter1, :filter2

def follow_function
#Doing the main portion
end

protected
def filter1
end

def filter2
end

end


In the class TestController has two filters, that will work on every action, there setting the instance variables on that filters, and using that in my follow_function. So the issues are when i am trying to call the follow_function from the delayed job method start_worker, i need to set the instance variables in that filters.


so what i tried something like that i put one function in TestController class like



def init_variables(names)
#filter1(names)
#filter2(names)
end

class TestDelay < ActiveRecord::Base
def start_worker
class_name.init_variables(params)
end
end


and i tried to passing arguments in before_filter, but its totally failed and getting weird. Is this the correct way to do this?


Aucun commentaire:

Enregistrer un commentaire