It almost seemed that there was no easy way out of putting application scope variables in the database.
But there is a way out:
if Thread.main[:uuid] == nil
Thread.main[:uuid]=0
end
uid = Thread.main[:uuid] += 1
This code accesses the mail thread of the rails process and puts a variable on it. (the thread is an object and can have key => value sets)
And since rails has only one main thread... its shared with all the threads underneath.
Good Luck
This is a pretty nice find -- thanks for sharing! It would be nice if there was an approach for persistent, application-level objects that was endorsed by the Rails team.
ReplyDeleteThanks Justin
ReplyDeleteAnyway, I would rather have a better solution then to write on the main thread, endorsed by the rails people.