How do I run a slow running batch Asynchronously, specifically a SVN post-commit?

落花浮王杯 提交于 2019-12-13 07:09:40

问题


I have a slow running batch file that compiles a log of changes and then emails a user. I would like it not to cause the user's commits to perform slowly in TortoiseSVN.

@ECHO OFF
SET REPOS=%1
SET REV=%2
SET DIR=%REPOS%/hooks
SET PATH=%PATH%;%DIR%;C:\Utils 
SET WORKING_COPY=C:\path\to\local\copy\
SET SITENAME=MySiteName
SET SMTP_SERVER=11.11.11.11
SET EMAIL_TO=my@email.email
SET EMAIL_FROM=my@email.email
SET SUBJECT=SVN Update - %SITENAME% - rev %REV% - %REPOS%

svn cleanup %WORKING_COPY%
svn update %WORKING_COPY%


ECHO The following changes were made to the code: > %DIR%/email.txt
ECHO. >> %DIR%/email.txt


svn log %WORKING_COPY% -v -r "%REV%" >> %DIR%/email.txt


svn diff %WORKING_COPY% -c "%REV%" --no-diff-deleted >> %DIR%/email.txt


sendEmail -s %SMTP_SERVER% -t %EMAIL_TO% -f %EMAIL_FROM% -u "%SUBJECT%" -o message-file=%DIR%/email.txt

I realised that this was running slowly, so I moved it to another file "email-changes.bat" and created a simple batch to call this batch asynchronously.

@ECHO OFF
#START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log

If I comment out the "START" line it runs and finishes instantly. If I remove the comment it takes forever to complete. I thought that should allow the post-commit to return to SVN quickly.

Is there any way I can get the code to not hang in Subversion, but still complete the emailing task in the background?


回答1:


Try starting the real hook script in a separate process:

@ECHO OFF
cmd.exe /c START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log

if that doesn't work, find a tool that can start another bat file in a separate process/thread.



来源:https://stackoverflow.com/questions/5819742/how-do-i-run-a-slow-running-batch-asynchronously-specifically-a-svn-post-commit

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