Skip to content

Commit

Permalink
refactor: log location
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet committed Oct 20, 2024
1 parent a6c3596 commit 570b97c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
21 changes: 13 additions & 8 deletions templates/common/__test__/get.location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ describe('get-location script template', () => {
throw new Error('Failed');
},
);
assert.equal(spy.mock.callCount(), 3);
assert.equal(spy.mock.callCount(), 1);

const location = String(spy.mock.calls[0]?.arguments[0]);
assert.equal(location, 'Location: s3://linz-workflows-scratch/2024-10/02-test-get-location-29l4x/');
const logOutputDict = JSON.parse(String(spy.mock.calls[0]?.arguments[0])) as { time: number };

const bucket = String(spy.mock.calls[1]?.arguments[0]);
assert.equal(bucket, 'Bucket: linz-workflows-scratch');

const key = String(spy.mock.calls[2]?.arguments[0]);
assert.equal(key, 'Key: 2024-10/02-test-get-location-29l4x');
// override time
logOutputDict.time = 1724037007216;

assert.deepEqual(logOutputDict, {
time: 1724037007216,
level: 20,
pid: 1,
msg: 'Workflow:Location',
location: 's3://linz-workflows-scratch/2024-10/02-test-get-location-29l4x/',
bucket: 'linz-workflows-scratch',
key: '2024-10/02-test-get-location-29l4x',
});
assert.deepEqual(shimRequired, ['node:fs']);
});
});
22 changes: 15 additions & 7 deletions templates/common/get.location.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ spec:
const argoTemplate = JSON.parse(process.env['ARGO_TEMPLATE']);
const podArchiveLoc = argoTemplate.archiveLocation.s3;
const workflowArchiveKey = podArchiveLoc.key.substr(0, podArchiveLoc.key.lastIndexOf('/'));
const location = `s3://${podArchiveLoc.bucket}/${workflowArchiveKey}/`
console.log(`Location: ${location}`);
console.log(`Bucket: ${podArchiveLoc.bucket}`);
console.log(`Key: ${workflowArchiveKey}`);
const key = podArchiveLoc.key.substr(0, podArchiveLoc.key.lastIndexOf('/'));
const bucket = podArchiveLoc.bucket;
const location = `s3://${bucket}/${key}/`
fs.writeFileSync('/tmp/location', location);
fs.writeFileSync('/tmp/bucket', `${podArchiveLoc.bucket}`);
fs.writeFileSync('/tmp/key', `${workflowArchiveKey}`);
fs.writeFileSync('/tmp/bucket', bucket);
fs.writeFileSync('/tmp/key', key);
console.log(JSON.stringify({
time: Date.now(),
level: 20,
pid: 1,
msg: 'Workflow:Location',
location,
bucket,
key,
}),)

0 comments on commit 570b97c

Please sign in to comment.