class CommitScheduler(object): def __init__(self, repo_name, repo_path, since_date = datetime.now()): self._repo_name = repo_name self._repo_path = repo_path self._commit_parser = CommitParser(repo_name) self._since_date = since_date self._until_date = since_date + ONE_MINUTE_TIME_DELTA def __to_commit_tuples(self, commits): return [commit.to_tuple() for commit in commits] def job(self): logging.info("start job ... repo_name:{0} - since_date:{1} - until_date:{2}".format( self._repo_name, self._since_date, self._until_date)) try: commits = self._commit_parser.get_needed_commit_message(self._since_date, self._until_date) except Exception: logging.error("parser commit failed ...") else: if len(commits) > 0: logging.debug("start insert into table ...") commitdao.batch_add_commits(self.__to_commit_tuples(commits)) self._since_date = self._until_date self._until_date = self._until_date + ONE_MINUTE_TIME_DELTA def run(self): os.chdir(self._repo_path) schedule.every(FREQUENCE).minutes.do(self.job)
def __init__(self, repo_name, repo_path, since_date = datetime.now()): self._repo_name = repo_name self._repo_path = repo_path self._commit_parser = CommitParser(repo_name) self._since_date = since_date self._until_date = since_date + ONE_MINUTE_TIME_DELTA
def parse_commit(self, commit): parsed_commit = CommitParser(commit) return parsed_commit.to_map()