Delayed_job Won't Run User defined method

家住魔仙堡 提交于 2019-12-06 05:52:02

This doesn't indicate that something is wrong:

the delayed_job table contains all the information loaded elsewhere in action_name

That would be expected in this case because you're saying this:

self.delay.test_case

and self is the controller that happens to have params and all sorts of other stuff you probably don't care about; DJ will have to serialize self in order to provide the appropriate context for test_case to run. Perhaps you're running into a size limit somewhere with that big file stuck in self.

I think your second "call delay on something else" approach is moving in the right direction.

You could try enquiring a job class:

class ItsAJob
    def perform
        u = User.new
        u.first_name = "JimBob"
        u.last_name = "joe"
        u.email = "itworked@eureka.com"
        u.password = "sailsJ123"
        u.password_confirmation = "sailsJ123"
        u.save
    end
end

# and elsewhere...
Delayed::Job.enqueue(ItsAJob.new)

Or try making your method a class method so you can .delay on a class:

class YourController
    def action_name
        self.class.delay.test_case
    end

    def self.test_case
        u = User.new
        u.first_name = "JimBob"
        u.last_name = "joe"
        u.email = "itworked@eureka.com"
        u.password = "sailsJ123"
        u.password_confirmation = "sailsJ123"
        u.save
    end

end

You cannot delay #save on ActiveRecord models since DJ will attempt to reload the model from the database before performing your action. All of the data will be lost. Instead, create a Job class with a #perform method that creates the User.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!