Skip to content

feat: add support for pfop workflow template #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ jobs:
QINIU_TEST_DOMAIN: ${{ secrets.QINIU_TEST_DOMAIN }}
- name: Upload coverage reports
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGE LOG

## 7.14.0
- 对象存储,持久化处理支持工作流模版
- 对象存储,修复持久化处理闲时任务的类型声明

## 7.13.0
- 对象存储,新增空间级别上传加速开关
- 对象存储,优化断点续传开启方式
Expand Down
16 changes: 12 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,11 @@ export declare namespace fop {
* 为 `1` 时开启闲时任务
*/
type?: number;

/**
* 工作流模版 ID,与函数参数中的 fops 参数二选一
*/
workflowTemplateID?: string
}
class OperationManager {
mac: auth.digest.Mac;
Expand All @@ -1066,7 +1071,7 @@ export declare namespace fop {
* 发送持久化数据处理请求
* @param bucket 空间名称
* @param key 文件名称
* @param fops 处理指令集合
* @param fops 处理指令集合,与 options.workflowTemplateID 二选一
* @param pipeline 处理队列名称
* @param options
* @param callback
Expand Down Expand Up @@ -1097,15 +1102,17 @@ export declare namespace fop {
reqid: string,
inputBucket: string,
inputKey: string,
creationDate: string,
type: number,
creationDate?: string,
type?: number,
taskFrom?: string,
items: {
cmd: string,
code: number,
desc: string,
returnOld: number,
error?: string,
hash?: string,
key?: string,
}[]
}>
): void;
Expand Down Expand Up @@ -1779,7 +1786,8 @@ export declare namespace rs {
persistentOps?: string;
persistentNotifyUrl?: string;
persistentPipeline?: string;
persistentType?: string;
persistentType?: number;
persistentWorkflowTemplateID?: string;

fsizeLimit?: number;
fsizeMin?: number;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qiniu",
"version": "7.13.0",
"version": "7.14.0",
"description": "Node wrapper for Qiniu Resource (Cloud) Storage API",
"main": "index.js",
"directories": {
Expand Down
15 changes: 12 additions & 3 deletions qiniu/fop.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function OperationManager (mac, config) {
* @param {string} [options.notifyURL] 回调业务服务器,通知处理结果
* @param {boolean} [options.force] 是否强制覆盖已有的同名文件
* @param {string} [options.type] 为 `1` 时,开启闲时任务
* @param {string} [options.workflowTemplateID] 工作流模板 ID
* @param {OperationCallback} callbackFunc 回调函数
*/
OperationManager.prototype.pfop = function (
Expand All @@ -38,9 +39,12 @@ OperationManager.prototype.pfop = function (
// 必须参数
const reqParams = {
bucket: bucket,
key: key,
fops: fops.join(';')
key: key
};
// `fops` is optional by could use `options.workflowTemplateID` to work
if (Array.isArray(fops)) {
reqParams.fops = fops.join(';');
}

// pipeline
if (!pipeline) {
Expand All @@ -57,9 +61,14 @@ OperationManager.prototype.pfop = function (
reqParams.force = 1;
}

// workflowTemplateID
if (options.workflowTemplateID) {
reqParams.workflowTemplateID = options.workflowTemplateID;
}

const persistentType = parseInt(options.type, 10);
if (!isNaN(persistentType)) {
reqParams.type = options.type;
reqParams.type = persistentType;
}

util.prepareZone(this, this.mac.accessKey, bucket, function (err, ctx) {
Expand Down
5 changes: 3 additions & 2 deletions qiniu/storage/rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1692,10 +1692,11 @@ function _putPolicyBuildInKeys () {
* @property {string} [callbackBody]
* @property {string} [callbackBodyType]
* @property {number} [callbackFetchKey]
* @property {string} [persistentOps]
* @property {string} [persistentOps] conflict with `persistentWorkflowTemplateID`
* @property {string} [persistentNotifyUrl]
* @property {string} [persistentPipeline]
* @property {string} [persistentType]
* @property {number} [persistentType]
* @property {string} [persistentWorkflowTemplateID] conflict with `persistentOps`
* @property {number} [fsizeLimit]
* @property {number} [fsizeMin]
* @property {string} [mimeLimit]
Expand Down
89 changes: 86 additions & 3 deletions test/fop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ describe('test start fop', function () {

it(`test pfop with upload; ${msg}`, function () {
const formUploader = new qiniu.form_up.FormUploader(config);
const key = 'qiniu-pfop-upload-file';
const key = 'test-pfop/upload-file';
const persistentKey = [
'qiniu-pfop-by-upload',
'persistentType',
'test-pfop/test-pfop-by-upload',
'type',
persistentType
].join('_');

Expand Down Expand Up @@ -179,4 +179,87 @@ describe('test start fop', function () {
});
});
});

it('test pfop by templateID with api', function () {
const srcKey = 'qiniu.mp4';
const srcBucket = bucketName;

const templateID = 'test-workflow';
const operationManager = new qiniu.fop.OperationManager(mac, config);

new Promise((resolve, reject) => {
operationManager.pfop(
srcBucket,
srcKey,
null,
null,
{ workflowTemplateID: templateID },
function (err, respBody, respInfo) {
if (err) {
reject(err);
return;
}
resolve({ data: respBody, resp: respInfo });
}
);
})
.then(({ data }) => {
data.should.have.keys('persistentId');
return new Promise((resolve, reject) => {
operationManager.prefop(
data.persistentId,
function (err, respBody, respInfo) {
if (err) {
reject(err);
return;
}
resolve({ data: respBody, resp: respInfo });
}
);
});
})
.then(({ data }) => {
data.should.have.keys(
'creationDate',
'taskFrom'
);
});
});

it('test pfop by templateID with upload', function () {
const formUploader = new qiniu.form_up.FormUploader(config);
const key = 'qiniu-pfop-tplid-upload-file';
const templateID = 'test-workflow';
const options = {
scope: bucketName,
persistentWorkflowTemplateID: templateID
};
const putPolicy = new qiniu.rs.PutPolicy(options);
const uploadToken = putPolicy.uploadToken(mac);
const putExtra = new qiniu.form_up.PutExtra();

return formUploader.put(uploadToken, key, testFilePath, putExtra)
.then(({ data }) => {
data.should.have.keys('key', 'persistentId');
return new Promise((resolve, reject) => {
new qiniu.fop.OperationManager(mac, config)
.prefop(
data.persistentId,
function (err, respBody, respInfo) {
if (err) {
reject(err);
return;
}
resolve({ data: respBody, resp: respInfo });
}
);
});
})
.then(({ data }) => {
data.should.have.keys(
'creationDate',
'taskFrom'
);
});
});
});
Loading