Rake task to update repositories failing
Added by Nathan Howell over 14 years ago
Hi all, hopefully someone can clue me in on what I'm missing here...
I've written a small rake task for our Redmine install that just updates a source code repository. I'll quickly describe how I use it, then describe the problem I'm having.
I have a git hook script that posts some data into couchdb whenever a commit is made. A background job processor (written in perl, for now) picks up the job from couchdb and runs a script to process the job. That script calls rake, which runs my task. (The reason I'm trying to run it this way is that doing the update directly from the git hook script really slows down commits.)
This all works perfectly if I run it from the shell myself, but running the exact same command from the perl script fails. The odd part is where it's failing. I'm running the background job processor under supervisord, so I can see any output from the running jobs easily. The rake task boots Rails, retrieves the correct data, but then the method call that actually does the repository update just doesn't happen. Here's the code from the task:
rs = Repository.find(:all, :conditions => ["url like ?", "%/#{ENV['SCM_LOC']}"]) puts rs.inspect rs.each { |r| puts r.inspect r.fetch_changesets }
Both puts statements show the right data when running either from the command line or the background script. But the fetch_changesets call only works when the task is called from the command line manually. Hopefully I've made some sense... any idea what I'm missing?
Replies (3)
RE: Rake task to update repositories failing
-
Added by Felix Schäfer over 14 years ago
That seems like a lot of trouble to find a repository, but maybe you have many projects attached to one repository? Anyway, see #3667 for inspiration on how to get there easier.
That won't alleviate the fetch_changesets problem though, but I'd wager your $PATH is off in the delayed job, though I find it very disturbing it takes that long that you want to delay it… What version of redmine are you running? I seem to remember that some updates a couple of weeks ago were intended to speed up the update of git repositories.
RE: Rake task to update repositories failing
-
Added by Nathan Howell over 14 years ago
I'm running 0.9.0, and updating that is on my todo list. Doing the update directly in the git hook seems to take about 3-6 seconds, which is enough to be annoying when compared to the usual speed of git commits (but maybe I'm picky...). I already have this background job system, so I thought it would be an easy solution to pass the task off to it. That way, the update still happens immediately, but it doesn't make my commit slower.
Your method in #3667 seems similar, but with our setup, I have to find the repository by its path, not the project identifier (unfortunately). My way is messier, but we end up at the same place.
Anyway, you were right with the $PATH suggestion. Setting it fixes the problem. Thanks very much.
RE: Rake task to update repositories failing
-
Added by Felix Schäfer over 14 years ago
Yeah, 3-6 seconds is a lot. Maybe you could try the direct hook again after upgrading :-)
And I'm glad you solved your problem.