35 lines
962 B
Go
35 lines
962 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"math/rand"
|
|
"path/filepath"
|
|
"strconv"
|
|
"time"
|
|
|
|
schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler"
|
|
cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
|
|
)
|
|
|
|
func MakeJobOutputFullPath(stgDir string, userID cdssdk.UserID, jobID schsdk.JobID) string {
|
|
return filepath.Join(stgDir, strconv.FormatInt(int64(userID), 10), "jobs", string(jobID), "output")
|
|
}
|
|
|
|
func MakeResourcePackageName(jobID schsdk.JobID) string {
|
|
return fmt.Sprintf("%s@%s", string(jobID), time.Now().Format("2006-01-02 15:04:05"))
|
|
}
|
|
|
|
func GenerateRandomID() string {
|
|
currentTime := time.Now().UnixNano() / int64(time.Millisecond)
|
|
rand.Seed(currentTime)
|
|
randomNum := rand.Intn(1000) // 0 到 999 之间的随机整数
|
|
idBase := fmt.Sprintf("%d%03d", currentTime, randomNum)
|
|
hasher := sha256.New()
|
|
hasher.Write([]byte(idBase))
|
|
hashBytes := hasher.Sum(nil)
|
|
hashedID := hex.EncodeToString(hashBytes)
|
|
return hashedID
|
|
}
|