All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tencent.devops.common.web.utils.AtomRuntimeUtil.kt Maven / Gradle / Ivy

The newest version!
package com.tencent.devops.common.web.utils

import com.tencent.devops.common.redis.RedisOperation

object AtomRuntimeUtil {

    fun getRunningAtomValue(
        redisOperation: RedisOperation,
        buildId: String,
        vmSeqId: String
    ): Pair? {
        val atomValue = redisOperation.get(
            getRunningAtomKey(buildId = buildId, vmSeqId = vmSeqId)
        ) ?: return null
        val atomValueSplit = atomValue.split(":")
        return if (atomValueSplit.size == 2) {
            Pair(atomValueSplit[0], atomValueSplit[1])
        } else {
            Pair(atomValueSplit[0], "")
        }
    }

    fun setRunningAtomValue(
        redisOperation: RedisOperation,
        buildId: String,
        vmSeqId: String,
        atomCode: String,
        signToken: String,
        expiredInSecond: Long
    ) {
        redisOperation.set(
            key = getRunningAtomKey(buildId = buildId, vmSeqId = vmSeqId),
            value = "$atomCode:$signToken",
            expiredInSecond = expiredInSecond
        )
    }

    fun deleteRunningAtom(
        redisOperation: RedisOperation,
        buildId: String,
        vmSeqId: String
    ) {
        redisOperation.delete(getRunningAtomKey(buildId = buildId, vmSeqId = vmSeqId))
    }

    private fun getRunningAtomKey(buildId: String, vmSeqId: String): String {
        return "sensitiveApi:atomCode:$buildId:$vmSeqId"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy