Skip to content

Commit

Permalink
feat: 签名模块后台逻辑优化 #4885 新增多codesign匹配功能
Browse files Browse the repository at this point in the history
  • Loading branch information
royalhuang committed Aug 28, 2021
1 parent a31f45f commit 3c61811
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 50 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.tencent.devops.sign.api.pojo.IpaInfoPlist
import com.tencent.devops.sign.api.pojo.IpaSignInfo
import com.tencent.devops.sign.api.pojo.MobileProvisionInfo
import com.tencent.devops.sign.api.pojo.SignDetail
import com.tencent.devops.sign.config.CodeSignProperties
import com.tencent.devops.sign.service.ArchiveService
import com.tencent.devops.sign.service.FileService
import com.tencent.devops.sign.service.MobileProvisionService
Expand All @@ -51,27 +50,31 @@ import com.tencent.devops.sign.utils.SignUtils.APP_INFO_PLIST_FILENAME
import com.tencent.devops.sign.utils.SignUtils.MAIN_APP_FILENAME
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.io.File
import java.io.InputStream
import java.util.regex.Pattern

@Service
@EnableConfigurationProperties(CodeSignProperties::class)
@Suppress("TooManyFunctions")
class SignServiceImpl @Autowired constructor(
private val fileService: FileService,
private val signInfoService: SignInfoService,
private val archiveService: ArchiveService,
private val mobileProvisionService: MobileProvisionService,
private val codeSignProperties: CodeSignProperties
private val mobileProvisionService: MobileProvisionService
) : SignService {
companion object {
private val logger = LoggerFactory.getLogger(SignServiceImpl::class.java)
const val DEFAULT_CODESIGN_PATH = "/usr/bin/codesign"
}

@Value("\${codesign.paths.version1:#{null}}")
private val codesignPathVersion1: String? = null

@Value("\${codesign.paths.version2:#{null}}")
private val codesignPathVersion2: String? = null

override fun uploadIpaAndDecodeInfo(
resignId: String,
ipaSignInfo: IpaSignInfo,
Expand Down Expand Up @@ -483,11 +486,12 @@ class SignServiceImpl @Autowired constructor(
}

private fun getCodeSignFile(version: String?): String {
logger.info("SIGN| codeSignProperties=$codeSignProperties")
return if (version.isNullOrBlank()) {
DEFAULT_CODESIGN_PATH
} else {
codeSignProperties.paths?.get(version) ?: DEFAULT_CODESIGN_PATH
logger.info("SIGN|codesignPathVersion1=$codesignPathVersion1" +
"|codesignPathVersion2=$codesignPathVersion2")
return when (version) {
"version1" -> codesignPathVersion1 ?: DEFAULT_CODESIGN_PATH
"version2" -> codesignPathVersion2 ?: DEFAULT_CODESIGN_PATH
else -> DEFAULT_CODESIGN_PATH
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AsyncSignService(
taskPoolSize ?: DEFAULT_TASK_POOL_SIZE,
0L,
TimeUnit.MILLISECONDS,
LinkedBlockingQueue(taskQueueSize ?: 5)
LinkedBlockingQueue(taskQueueSize ?: DEFAULT_TASK_QUEUE_SIZE)
)

fun asyncSign(
Expand All @@ -74,7 +74,12 @@ class AsyncSignService(
signExecutorService.execute {
val start = LocalDateTime.now()
logger.info("[$resignId] asyncSign start")
val success = signService.signIpaAndArchive(resignId, ipaSignInfo, ipaFile, taskExecuteCount)
val success = signService.signIpaAndArchive(
resignId = resignId,
ipaSignInfo = ipaSignInfo,
ipaFile = ipaFile,
taskExecuteCount = taskExecuteCount
)
logger.info("[$resignId] asyncSign finished with success:$success")
signBean.signTaskFinish(
elapse = LocalDateTime.now().timestampmilli() - start.timestampmilli(),
Expand Down Expand Up @@ -107,7 +112,7 @@ class AsyncSignService(
override fun destroy() {
// 当有签名任务执行时,阻塞服务的退出
signExecutorService.shutdown()
while (!signExecutorService.awaitTermination(5, TimeUnit.SECONDS)) {
while (!signExecutorService.awaitTermination(EXECUTOR_DESTROY_AWAIT_SECOND, TimeUnit.SECONDS)) {
logger.warn("SignTaskBean still has sign tasks.")
}
}
Expand All @@ -126,5 +131,7 @@ class AsyncSignService(
companion object {
private val logger = LoggerFactory.getLogger(AsyncSignService::class.java)
const val DEFAULT_TASK_POOL_SIZE = 10
const val DEFAULT_TASK_QUEUE_SIZE = 5
const val EXECUTOR_DESTROY_AWAIT_SECOND = 5L
}
}

0 comments on commit 3c61811

Please sign in to comment.