Skip to content

Commit

Permalink
Clean up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Oct 24, 2024
1 parent 4553bad commit 2f6439c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
20 changes: 12 additions & 8 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function handleNewFile(filePath, queue, metricsLogger) {
}

async function start() {
console.log('Starting Animl Base');
console.log('---------------------------------\n');
console.log('\nStarting Animl Base');

// Starting Buckeye software
let mbase = new Multibase(config);
Expand All @@ -58,16 +59,19 @@ async function start() {
// Initialize directory watcher
const imgWatcher = chokidar.watch(config.imgDir, config.watcher);
imgWatcher
.on('ready', () => console.log(`Watching for changes to ${config.imgDir}`))
.on('ready', async () => {
console.log(`Watching for changes to ${config.imgDir}`);

// NOTE: just for testing
// const filesWatchedOnStart = imgWatcher.getWatched();
// Object.keys(filesWatchedOnStart).forEach((dir) => {
// console.log(`Number of files in ${dir} ON START: ${filesWatchedOnStart[dir].length}`);
// console.log(`First image in directory: ${filesWatchedOnStart[dir][0]}`);
// });
})
.on('add', (path) => handleNewFile(path, queue, metricsLogger))
.on('error', (err) => console.log(`imgWatcher error: ${err}`));

// // Just for testing...
// const filesWatched = imgWatcher.getWatched();
// Object.keys(filesWatched).forEach((dir) => {
// console.log(`Number of files in ${dir} : ${filesWatched[dir].length}`);
// });

// Initialize worker
let worker = new Worker(config, queue, imgWatcher);
await worker.init();
Expand Down
15 changes: 4 additions & 11 deletions src/utils/multibase.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@ class Multibase {
const output = { out: [], err: [], exitCode: null };
const opts = { shell: true };
const mbase = args ? spawn(cmd, args, opts) : spawn(cmd, opts);
mbase.stdout.on('data', (data) => {
console.log('mbase stdout: ', data.toString());
output.out.push(data.toString());
});
mbase.stderr.on('data', (data) => {
console.error('mbase stderr: ', data.toString());
output.err.push(data.toString());
});
mbase.stdout.on('data', (data) => output.out.push(data.toString()));
mbase.stderr.on('data', (data) => output.err.push(data.toString()));
mbase.on('exit', (code) => {
console.log(`mbase exited with code ${code}`);
output.exitCode = code;
resolve(output);
});
Expand All @@ -36,16 +29,16 @@ class Multibase {
running = false;
}
}
console.log('Multibase SE running? ', running);
return running;
}
}

async start() {
if (this.config.platform === 'linux') {
console.log('Linux detected, starting Buckeye Multibase SE');
console.log('Linux detected, checking Buckeye Multibase SE state...');
const running = await this.isRunning();
if (!running) {
console.log('Starting Buckeye Multibase SE...');
await this.exec('mbasectl', ['-s']);
}
} else if (this.config.platform === 'win32') {
Expand Down
7 changes: 1 addition & 6 deletions src/utils/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ class Worker {
try {
// get first job & process
console.log('Queue length: ', this.queue.size);

const img = await this.queue.getFirst();
await this.s3.upload(img.path);
console.log('Upload success');
await this.queue.remove(img.path);
await this.imgWatcher.unwatch(img.path); // TODO: test whether this works

// // Just for testing...
// const filesWatched = this.imgWatcher.getWatched();
// Object.keys(filesWatched).forEach((dir) => {
// console.log(`Number of files in ${dir} : ${filesWatched[dir].length}`);
// });

// Reset backoff and poll again
this.backoff.reset();
this.poll();
Expand Down

0 comments on commit 2f6439c

Please sign in to comment.