我按照本文的方法计算令牌使用量,然后计算成本。我在工作项 oncomplete 回调上运行以下计算并将其存储在数据库中。
function getJobMetrics(jobDetails) {
const { stats } = jobDetails.jobStatus;
const timeQueued = Date.parse(stats.timeQueued);
const timeDownloadStarted = Date.parse(stats.timeDownloadStarted);
const timeUploadEnded = Date.parse(stats.timeUploadEnded);
const timeInstructionsStarted = Date.parse(stats.timeInstructionsStarted);
const timeInstructionsEnded = Date.parse(stats.timeInstructionsEnded);
const queueDelay = timeDownloadStarted - timeQueued;
const downloadDelay = timeInstructionsStarted - timeDownloadStarted;
const instructionsRunDuration = timeInstructionsEnded - timeInstructionsStarted;
const totalDuration = timeInstructionsEnded - timeQueued;
// https://aps.autodesk.com/blog/estimate-design-automation-costs
// in case of failure, timeUploadEnded is null
const adskCalculatedTimeTaken = (timeUploadEnded || timeInstructionsEnded) - timeDownloadStarted;
const adskTokenUsageInCloudCredits = (adskCalculatedTimeTaken / 1000 / 60 / 60) * 6;
return {
adskDasQueueDelay: queueDelay,
adskDasDownloadDelay: downloadDelay,
adskDasInstructionsRunDuration: instructionsRunDuration,
adskDasTotalDuration: totalDuration,
adskDasTotalBytesDownloaded: stats.bytesDownloaded,
adskCalculatedTimeTaken,
adskTokenUsageInCloudCredits,
};
}
当我汇总adskTokenUsageInCloudCredits
一个月内的所有工作项时,它与我在 APS 分析仪表板上看到的数字不匹配。我的数字似乎高出一个数量级。我没有找到任何可以查询消耗令牌的单个事件的 API。我做错了什么?