gitlink定制:gitee和github分开同步
This commit is contained in:
parent
1aea01d55f
commit
518f37275d
|
@ -97,6 +97,16 @@ class JobService(Service):
|
|||
data.append(self._do_to_dto(job))
|
||||
return data
|
||||
|
||||
async def source_list_jobs(self, source: Optional[str] = None) -> Optional[List[JobDTO]]:
|
||||
cond = None
|
||||
if source is not None:
|
||||
cond = text(f"status = 1 and {source} is not null")
|
||||
all = await self._job_dao.fetch(cond)
|
||||
data = []
|
||||
for job in all:
|
||||
data.append(self._do_to_dto(job))
|
||||
return data
|
||||
|
||||
async def get_job(self, id: int) -> Optional[JobDTO]:
|
||||
job = await self._job_dao.fetch(text(f"id = {id}"))
|
||||
if not job:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import asyncio
|
||||
import sys
|
||||
import json
|
||||
import time
|
||||
sys.path.append('..') # NOQA: E402
|
||||
|
||||
from src.service.sync import JobService, ProjectService
|
||||
|
@ -117,23 +118,44 @@ async def sync():
|
|||
await log_service.delete_logs()
|
||||
# fetch the sync job list
|
||||
service = JobService()
|
||||
jobs = await service.list_jobs()
|
||||
if jobs is None:
|
||||
# jobs = await service.list_jobs()
|
||||
# if jobs is None:
|
||||
# logger.info(f"There are no sync jobs in the database")
|
||||
# return
|
||||
# logger.info(f"There are {len(jobs)} sync jobs in the database")
|
||||
#
|
||||
# tasks = []
|
||||
# for job in jobs:
|
||||
# # if the job status is green, it means we can sync the job
|
||||
# if job.status == Color.green:
|
||||
# await Log(LogType.INFO,
|
||||
# f"The gitlink branch {job.gitlink_branch} from {job.project} is now syncing", job.id)
|
||||
# task = asyncio.create_task(sync_job(job))
|
||||
# tasks.append(task)
|
||||
# else:
|
||||
# await Log(LogType.INFO,
|
||||
# f"The gitlink branch {job.gitlink_branch} from {job.project} does not need to sync", job.id)
|
||||
gitee_jobs = await service.source_list_jobs("gitee_branch")
|
||||
github_jobs = await service.source_list_jobs("github_branch")
|
||||
if gitee_jobs is None and github_jobs is None:
|
||||
logger.info(f"There are no sync jobs in the database")
|
||||
return
|
||||
logger.info(f"There are {len(jobs)} sync jobs in the database")
|
||||
logger.info(f"There are {len(gitee_jobs) + len(github_jobs)} sync jobs in the database")
|
||||
|
||||
tasks = []
|
||||
for job in jobs:
|
||||
# if the job status is green, it means we can sync the job
|
||||
if job.status == Color.green:
|
||||
await Log(LogType.INFO,
|
||||
f"The gitlink branch {job.gitlink_branch} from {job.project} is now syncing", job.id)
|
||||
task = asyncio.create_task(sync_job(job))
|
||||
tasks.append(task)
|
||||
else:
|
||||
await Log(LogType.INFO,
|
||||
f"The gitlink branch {job.gitlink_branch} from {job.project} does not need to sync", job.id)
|
||||
for job in gitee_jobs:
|
||||
await Log(LogType.INFO,
|
||||
f"The gitlink branch {job.gitlink_branch} from {job.project} is now syncing", job.id)
|
||||
task = asyncio.create_task(sync_job(job))
|
||||
tasks.append(task)
|
||||
|
||||
time.sleep(5)
|
||||
for job in github_jobs:
|
||||
await Log(LogType.INFO,
|
||||
f"The gitlink branch {job.gitlink_branch} from {job.project} is now syncing", job.id)
|
||||
task = asyncio.create_task(sync_job(job))
|
||||
tasks.append(task)
|
||||
|
||||
for task in tasks:
|
||||
await task
|
||||
logger.info("End syncing ****************************")
|
||||
|
|
Loading…
Reference in New Issue