@@ -138,6 +138,20 @@ def create_job(self, commit_id, clone_url, build_id, project_id, github_private_
138138 'Create Jobs', %s, false, '', 1, 1024, %s, %s, null)
139139 ''' , [build_id , project_id , json .dumps (git_repo ), env ], fetch = False )
140140
141+ def has_active_build (self , commit_id , project_id ):
142+ result = self .execute ('''
143+ SELECT count(*)
144+ FROM job
145+ JOIN build ON job.build_id = build.id
146+ JOIN "commit" ON build.commit_id = "commit".id and build.project_id = commit.project_id
147+ WHERE "commit".id = %s AND commit.project_id = %s AND job.state IN ('running', 'queued', 'scheduled')
148+ GROUP BY job.state
149+ ''' , [commit_id , project_id ])
150+
151+ if result :
152+ return True
153+
154+ return False
141155
142156 def create_push (self , c , repository , branch , tag ):
143157 if not c ['distinct' ]:
@@ -162,6 +176,9 @@ def create_push(self, c, repository, branch, tag):
162176
163177 commit_id = c ['id' ]
164178
179+ if self .has_active_build (commit_id , project_id ):
180+ return
181+
165182 if not result :
166183 status_url = repository ['statuses_url' ].format (sha = c ['id' ])
167184 result = self .execute ('''
@@ -364,6 +381,10 @@ def handle_pull_request(self, event):
364381 return res (200 , 'build already triggered' )
365382
366383 commit_id = result [0 ][0 ]
384+
385+ if self .has_active_build (commit_id , project_id ):
386+ return res (200 , 'build already triggered' )
387+
367388 build_id = self .create_build (commit_id , project_id )
368389 self .create_job (event ['pull_request' ]['head' ]['sha' ],
369390 event ['pull_request' ]['head' ]['repo' ]['clone_url' ],
0 commit comments