Skip to content

Commit

Permalink
Use async
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-boris committed May 10, 2022
1 parent efb9319 commit 1b37863
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions workers/docker-worker/src/features/bulk_log.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const Debug = require('debug');
const fs = require('mz/fs');
const streamClosed = require('../stream_closed');
const { tmpdir } = require('os');
const { mkdtempSync } = require('fs');
const { rm } = require('fs').promises;
const { mkdtemp, rm } = require('fs/promises');
const { join, sep } = require('path');
const uploadToS3 = require('../upload_to_s3');
const zlib = require('zlib');
Expand All @@ -24,7 +23,7 @@ class BulkLog {
}

async created(task) {
this.tmpDir = mkdtempSync(`${tmpdir()}${sep}`);
this.tmpDir = await mkdtemp(`${tmpdir()}${sep}`);
this.tmpFile = 'bulk_log';
this.filePath = join(this.tmpDir, this.tmpFile);
debug('Created BulkLog using tempfile: ' + this.filePath);
Expand Down
5 changes: 2 additions & 3 deletions workers/docker-worker/src/features/chain_of_trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const Debug = require('debug');
const fs = require('mz/fs');
const streamClosed = require('../stream_closed');
const { tmpdir } = require('os');
const { mkdtempSync } = require('fs');
const { rm } = require('fs').promises;
const { mkdtemp, rm } = require('fs/promises');
const { join, sep } = require('path');
const uploadToS3 = require('../upload_to_s3');
const zlib = require('zlib');
Expand All @@ -30,7 +29,7 @@ class ChainOfTrust {
this.ed25519Key = Buffer.from(await new Promise((accept, reject) =>
fs.readFile(task.runtime.ed25519SigningKeyLocation, 'ascii', (err, data) => err ? reject(err) : accept(data))), 'base64');

this.tmpDir = mkdtempSync(`${tmpdir()}${sep}`);
this.tmpDir = await mkdtemp(`${tmpdir()}${sep}`);
this.tmpFile = 'chain_of_trust';
this.filePath = join(this.tmpDir, this.tmpFile);
debug(`created temporary file: ${this.filePath}`);
Expand Down
8 changes: 4 additions & 4 deletions workers/docker-worker/src/upload_to_s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const https = require('https');
const url = require('url');
const fs = require('mz/fs');
const { tmpdir } = require('os');
const { mkdtempSync, rmSync, writeFileSync } = require('fs');
const { mkdtemp, rm, writeFile } = require('fs/promises');
const { join, sep } = require('path');
const promiseRetry = require('promise-retry');
const { createLogger } = require('./log');
Expand All @@ -30,7 +30,7 @@ module.exports = async function uploadToS3 (
httpOptions,
compress)
{
const tmpDir = mkdtempSync(`${tmpdir()}${sep}`);
const tmpDir = await mkdtemp(`${tmpdir()}${sep}`);
const tmpFile = 'upload_to_s3';
const tmpFilePath = join(tmpDir, tmpFile);
debug(`created temporary file ${tmpFilePath} for ${artifactName}`);
Expand All @@ -54,7 +54,7 @@ module.exports = async function uploadToS3 (
// write the source out to a temporary file so that it can be
// re-read into the request repeatedly
if (typeof source === 'string') {
writeFileSync(tmpFilePath, source);
await writeFile(tmpFilePath, source);
hash.update(source);
} else {
let stream = fs.createWriteStream(tmpFilePath);
Expand Down Expand Up @@ -159,7 +159,7 @@ module.exports = async function uploadToS3 (
// Solving the equation for factor gives factor=1.311
}, { maxTimeout: 30000, factor: 1.311, randomize: true });
} finally {
rmSync(tmpDir, { recursive: true });
await rm(tmpDir, { recursive: true });
}

return { digest, size };
Expand Down

0 comments on commit 1b37863

Please sign in to comment.