use of org.commonjava.indy.subsys.git.GitManager in project indy by Commonjava.
the class RevisionsManager method setup.
@PostConstruct
public void setup() {
if (!revisionsConfig.isEnabled()) {
return;
}
try {
final File dataDir = dataFileManager.getDetachedDataBasedir();
final File gitignore = new File(dataDir, ".gitignore");
dataDir.mkdirs();
FileUtils.write(gitignore, join(DATA_DIR_GITIGNORES, "\n"));
final GitConfig dataConf = new GitConfig(dataDir, revisionsConfig.getDataUpstreamUrl(), true).setRemoteBranchName(revisionsConfig.getBranchName()).setUserEmail(revisionsConfig.getUserEmail());
dataFileGit = new GitManager(dataConf);
// we need a TimerTask that will commit modifications periodically
Timer timer = new Timer(true);
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
int committed = commitDataUpdates();
if (committed > 0) {
logger.info("Commit and push data updates, size: " + committed);
pushDataUpdates();
}
} catch (GitSubsystemException e) {
logger.warn("Failed to push data updates", e);
}
}
}, 1000, // every 1 min
60 * 1000);
} catch (GitSubsystemException | IOException e) {
throw new IllegalStateException("Failed to start revisions manager: " + e.getMessage(), e);
} finally {
}
}
Aggregations