工作流可以通过调用 audit 函数创建审计记录。audit 函数唯一的参数是要放置到审计日志中的字符串。
对于执行时间较长的复杂工作流,向执行工作流的用户提供明确的进度信息可能比较有用。要允许通过这种方式报告工作流的执行情况,execute 成员应该返回步骤数组。每个数组元素必须包含以下成员:
|
与整个工作流上的 execute 函数一样,每个步骤的 execute 成员都将包含工作流参数的对象作为参数。
示例 18 工作流执行报告例如,下面的工作流通过三个步骤创建新的项目、共享资源和审计记录:
var steps = [ { step: 'Checking for associated project', execute: function (params) { try { run('shares select ' + params.unit); } catch (err) { if (err.code != EAKSH_ENTITY_BADSELECT) throw (err); /* * We haven't yet created a project that corresponds to * this business unit; create it now. */ run('shares project ' + params.unit); set('mountpoint', '/export/' + params.unit); run('commit'); run('shares select ' + params.unit); } } }, { step: 'Creating share', execute: function (params) { run('filesystem ' + params.name); run('commit'); } }, { step: 'Creating audit record', execute: function (params) { audit('created "' + params.name + '" in "' + params.unit); } } ]; var workflow = { name: 'Create share', description: 'Creates a new share in a business unit', parameters: { name: { label: 'Name of new share', type: 'String' }, unit: { label: 'Business unit', type: 'ChooseOne', options: [ 'development', 'finance', 'qa', 'sales' ], optionlabels: [ 'Development', 'Finance', 'Quality Assurance', 'Sales/Administrative' ], } }, validate: function (params) { try { run('shares select ' + params.unit); run('select ' + params.name); } catch (err) { if (err.code == EAKSH_ENTITY_BADSELECT) return; } return ({ name: 'share already exists' }); }, execute: function (params) { return (steps); } };