[英]Handle multiple pulls in Local Git Repo
I have Sinatra service that updates a local git repo by executing git pull
when it is hit. 我有Sinatra服务,通过在被点击时执行
git pull
来更新本地git repo。 Since it is a write, I want only one git pull
to happen at a time. 既然是写操作,所以我一次只希望发生一次
git pull
。 How do I effectively detect if a pull
is already happening ? 如何有效检测是否已发生
pull
? Currently am just checking if index.lock
file exists in .git
directory. 目前,我只是检查
.git
目录中是否存在index.lock
文件。
if @file_obj.exists? "#{@data_dir}/.git/index.lock"
@log.info('********* LOCKED **********')
else
MUTEX.synchronize do
@log.info('********* Inside Sync **********')
@executor.run(git_pull_command, in: @data_dir)
end
end
index.lock
is probably the only file that you need to worry about. index.lock
可能是您唯一需要担心的文件。 Since you're using a mutex to synchronize your operations, this code should be fine. 由于您使用互斥锁来同步操作,因此此代码应该没问题。
Git only really creates the index.lock
file when it needs to have sole control over the index
for a while (and to prevent other Git processes from clobbering stuff). Git仅在需要唯一控制
index
一段时间(并防止其他Git进程破坏内容)时才真正创建index.lock
文件。 This would only happen while the pull is completing. 这只会在拉动完成时发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.