资产计算公用
所有资产计算无服务器行动所需的共同公用事业
安装
npm install @adobe/asset-compute-commons
API 细节
Adobe IO Eventions, New Relic 度量衡, 以及自定义出错等.
资产计算事件
发送 Adobe IO 事件的资产计算事件处理器
构造参数
AssetComputeEvents 构造器支持下列强制性参数:
- 段落: 对象必须包含授权参数:
auth.accessTokenorgId或者说auth.orgIdclientId或者说auth.clientId
AssetComputeEvents 构造器支持下列可选参数:
- 重试: 重试选项 节点重复 为发送 IO 事件。 (违约)
node-fetch-retry默认选项)
发送事件
这个 sendEvent 方法发送 Adobe IO 事件.
AssetComputeEvents.sendEvent 方法需要两个必要的参数: type 财务报告和审定财务报表 payload。 。 。 .
- 类型: 包含 Adobe IO 事件类型的字符串( 均不包含)
rendition_created或者说rendition_failed(中文(简体) ) - 有效载数: 含有事件有效载荷的对象
见 资产计算 API 文档: 同步事件 关于这个专题的更多信息
实例
带有自定义重试选项的示例 :
const { AssetComputeEvents } = require('@adobe/asset-compute-commons');
const params = {
auth: {
accessToken: '12345',
orgId: 'orgId',
clientId: 'clientId`
}
}
const retry = {
retryMaxDuration: 1000 // in ms
}
const eventsHandler = new AssetComputeEvents(params, retry);
await eventsHandler.sendEvent('rendition_created', {
rendition: {
name: 'rendition.jpg',
fmt: 'jpg'
}
});
有示例 rendition_failed 事件类型 :
const { AssetComputeEvents } = require('@adobe/asset-compute-commons');
const params = {
auth: {
accessToken: '12345',
orgId: 'orgId',
clientId: 'clientId`
}
}
const eventsHandler = new AssetComputeEvents(params);
await eventsHandler.sendEvent('rendition_failed', {
rendition: {
name: 'rendition.21',
fmt: '21'
},
errorReason: 'RenditionFormatUnsupported',
errorMessage: 'Rendition format `21` is not supported'
});
资产计算计量
资产计算处理器,用于发送新遗迹计量。 它使用节点js代理 节点- 开口whisk- newrelic 发送参数到新遗迹.
构造参数
AssetComputeMetrics 构造器支持下列强制性参数:
- 段落: 对象必须包含新遗迹度量参数:
newRelicEventsURL: 新的遗迹透视事件url(应该为形式:https://insights-collector.newrelic.com/v1/accounts/<YOUR_ACOUNT_ID>/events(中文(简体) )newRelicApiKey: 新的 Relic Insights API 密钥(参见"注册一个插入API密钥"一节) 这里(中文(简体) )
AssetComputeMetrics 构造器支持下列可选参数:
- 选项: 支持的其他新遗迹计量选项 节点- 开口whisk- newrelic
简单示例
启动度量衡处理器,发送度量衡并停止度量剂:
const { AssetComputeMetrics } = require('@adobe/asset-compute-commons');
const params = {
newRelicEventsURL: 'https://insights-collector.newrelic.com/v1/accounts/<YOUR_ACOUNT_ID>/events',
newRelicApiKey: 'YOUR_API_KEY',
// ... rest of the Asset Compute parameters
}
const metricsHandler = new AssetComputeMetrics(params);
const metrics = {
downloadDuration: 200,
size: 3000
}
await metricsHandler.sendMetrics('rendition', metrics);
await metricsHandler.activationFinished(); // see https://github.com/adobe/node-openwhisk-newrelic#usage for information about `activationFinished()`
其他额外职能
添加自定义度量衡 :
metricsHandler.add({
uuid: '12345',
count: 2
});
获取当前状态 metrics数字 :
console.log(metricsHandler.get()); // should print out metrics added in `metricsHandler.add()`
发送出错度量( 以事件类型发送度量) error:
const location = 'upload_worker_flite';
const message = 'Invalid file format';
const metrics = {
downloadDuration: 200,
size: 3000
}
await metricsHandler.sendErrorMetrics(location, message, metrics);
发送客户端错误衡量标准( 随事件类型发送衡量标准) client_error:
const location = 'upload_worker_flite';
const message = 'Invalid file format';
const metrics = {
downloadDuration: 200,
size: 3000
}
await metricsHandler.sendClientErrorMetrics(location, message, metrics);
以所抛出的例外发送出出错度量( 以事件类型表示的度量) client_error 或者说 error 取决于错误:
foo() {
try {
console.log('hello!');
} catch (error) {
metricsHandler.handleError(error, {
location: "mylocation",
message: "something failed",
metrics: {}
});
}
}
资产计算出错
资产计算工作者使用了若干自定义错误:
错误类型
| 类型 | 说明 | 属性 |
|---|---|---|
error | 出乎意料的错误和例外 | message, (中文(简体) ), date, (中文(简体) ), location |
client_error | 客户端配置错误导致的错误 | message, (中文(简体) ), date, (中文(简体) ), reason |
错误属性
message: 错误消息date: 当前在 UTC 中出现错误的时间location: 出错的地点(仅在类型中)error(中文(简体) )reason: 出错的原因(仅在客户端出错时)- 必须属于列表之一:"SourceFormatUnsuplied","RenditionFormatUsuplied","SourceUsuplied","SourceCorrupt","Rendition TooLarge" {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢
自定义出错
| 名称 | 说明 | 类型 |
|---|---|---|
SourceFormatUnsupportedError | 该源是一个不支持的类型. | 客户端出错 |
RenditionFormatUnsupportedError | 请求的格式不支持 . | 客户端出错 |
SourceUnsupportedError | 特定源不支持, 即使类型被支持 . | 客户端出错 |
SourceCorruptError | 源数据腐败. 包括空文件 . | 客户端出错 |
RenditionTooLargeError | 无法使用预签名的 URL 上传引渡文件 target。实际引渡规模作为元数据在 repo:size ,并且可以被客户端用来以正确的预先签名的 URL 数量来重新处理此递解. | 客户端出错 |
ArgumentError | 错误的参数( 类型、 结构等) | 错误 |
GenericError | 任何其它错误. | 错误 |
实例
在动作中下载源文件的一般性错误 worker-pie数字 :
const { GenericError } = require('@adobe/asset-compute-commons');
const message = 'Error while downloading source file!'
const location = 'download_worker_pie'
throw new GenericError(message, location);
租赁格式不支持 :
const { RenditionFormatUnsupportedError } = require('@adobe/asset-compute-commons');
const message = 'Rendition format `sdfg` is not supported'
throw new RenditionFormatUnsupportedError(message);
资产计算日志 Utils
从资产计算工人日志中删除敏感信息的水电费
实例
从日志编辑访问令牌 :
const { AssetComputeLogUtils } = require('@adobe/asset-compute-commons');
params = {
accessToken: '123453467',
fmt: 200
}
console.log("Asset Compute parameters:", AssetComputeLogUtils.redactUrl(params)); // should replace access token with "[...REDACTED...]"
用同样的日志打印 AssetComputeLogUtils.log 方法 :
const { AssetComputeLogUtils } = require('@adobe/asset-compute-commons');
params = {
accessToken: '123453467',
fmt: 200
}
AssetComputeLogUtils.log(params, "Asset Compute parameters"); // should replace access token with "[...REDACTED...]"
Apache 打开Whisk 动作名
一个简单的方法来获取关于Apache OpenWhisk动作的信息.
属性( 所有默认为空字符串)
- 名称: 基础 Apache OpenWhisk 动作名
- 软件包: Apache OpenWhisk 软件包名称
- 命名空间: Apache OpenWhisk 命名空间
- 全名: 全Apache OpenWhisk 动作名, 包括来自环境变量的命名空间、 软件包和动作名
__OW_ACTION_NAME
实例:
const actionInfo = new OpenwhiskActionName();
console.log(actionInfo.name) // prints out something like `worker-pie`
console.log(actionInfo.package) // prints package name, ex: `experimental`
console.log(actionInfo.namespace) // prints namespace, ex: `stage`
console.log(actionInfo.fullname) // prints full name, ex: /stage/experimental/worker-pie
同步事件
处理完成后, 或发生错误时, 事件会通过 Adobe I/O事件。事件是 JSON 对象 event 字段中 events 列表中的 jorunal 响应.
资产计算服务所有事件的I/O事件类型是 asset_compute。该日记将仅自动订阅此事件类型,预计消费者不会根据i/o事件类型过滤.
服务特定事件类型可在 type 属性.
事件类型
| 活动 | 说明 |
|---|---|
rendition_created | 为每一个成功处理并上传的引渡发送. |
rendition_failed | 每一次引渡都无法处理或上传. |
事件属性
| 属性 | 类型 | 活动 | 说明 |
|---|---|---|---|
date | string | * | 简化扩展发送事件的时间戳 ISO-8601 标准 格式(按 Javascript Date.to ISOString () (原始内容存档于2018-09-29)) (中文(简体) ). |
requestId | string | * | 原请求的编号 /process,与 X-Request-Id 头曰. |
source | object | * | 这个 source 会 议 日 程 和 议 程 /process 请求. |
userData | object | * | 这个 userData 会 议 日 程 和 议 程 /process 设置时请求. |
rendition | object | rendition_* | 相应的引渡对象传入 /process。 。 。 . |
metadata | object | rendition_created | 这个 元数据 引渡财产. |
errorReason | string | rendition_* | 租赁失败 原因 如果有的话. |
errorMessage | string | rendition_* | 如果引渡失败,则提供更详细的文字. |
元数据
| 财产 | 说明 |
|---|---|
tiff:ImageWidth | 以像素表示的引渡宽度 。 如果引渡不是形象,则不会在场. |
tiff:ImageLength | 以像素表示的引渡长度. 如果引渡不是形象,则不会在场. |
repo:size | 以字节表示的引渡大小 . |
repo:sha1 | 引渡的Sha1摘要. |
错误原因
| 原因 | 说明 |
|---|---|
SourceFormatUnsupported | 该源是一个不支持的类型. |
RenditionFormatUnsupported | 请求的格式不支持 . |
SourceUnsupported | 特定源不支持, 即使类型被支持 . |
SourceCorrupt | 源数据腐败. 包括空文件 . |
RenditionTooLarge | 无法使用预签名的 URL 上传引渡文件 target。实际引渡规模作为元数据在 repo:size ,并且可以被客户端用来以正确的预先签名的 URL 数量来重新处理此递解. |
GenericError | 任何其它错误. |
捐款
欢迎捐款! 读取 贡献指南 更多信息.
许可证发放
这个项目根据Apache V2许可证获得许可. 见 自由主义 更多信息.