I'm running a rails function as a delayed job. The problem is the session info that I had in place doesn't come across to the delayed job (I didn't expect it would). So my user is logged in and that log-in tells rails what postgres schema to hit.
Say user "dave" is assigned to schem 1.
He hits "run long process" with the id of the process as a parameter (say :id => 18).
DJ gets the action, but can't find the long_process record find(18) as it returns nil. There's no record in the public tables so it won't be found there.
I tried to pass in my current user token, and I could get it across to the function. But I can't do much with it there. I want to switch user for the local scope of current action, as it's the only one that has rights to the tables. The next action the DJ hits is likely not for the same user, so it shouldn't have rights to the previous users tables.
Edit...
in Upload module
def self.find_ex(id)
return ( (id.class == 'String' && id.count('-') > 0) ?
find_by_guid(id) : find(id) );
end
in a Upload Controller
def run_now
@upload = Upload.find_ex(params[:id]);
render :json=>@upload.to_hash(), status: 200
ew = EDMWorker.new
ew.runUploadJob(params[:id])
end
In it's own file
class EDMWorker
def runUploadJob(id)
upload = Upload.find_ex(id);
upload.run_job();
end
handle_asynchronously :runUploadJob, :priority => 10, :queue => 'public'
end
TOP OF ERROR REPORT IN DELAYED JOB TABLE
Couldn't find Upload with id=68
The first bit works. The object is found and rendered perfectly.
The data is in "1".uploads.
The call in the delayed job "action" is (I suspect) being called against "public".uploads which should always be empty.
I can't call sign_in(user) in the delay job class, because the function is undefined. So I'm at a loss. How can I get the delayed job worker to know which session created its task?