Skip to content

Additional dev queue consumer logging #1606

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 1 commit into from
Jan 13, 2025
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
25 changes: 22 additions & 3 deletions apps/webapp/app/v3/marqs/devQueueConsumer.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export class DevQueueConsumer {
return;
}

logger.debug("[DevQueueConsumer] Deprecating background worker", {
backgroundWorker: backgroundWorker.id,
env: this.env.id,
});

this._deprecatedWorkers.set(id, backgroundWorker);
this._backgroundWorkers.delete(id);
}
Expand All @@ -96,9 +101,10 @@ export class DevQueueConsumer {

this._backgroundWorkers.set(backgroundWorker.id, backgroundWorker);

logger.debug("Registered background worker", {
logger.debug("[DevQueueConsumer] Registered background worker", {
backgroundWorker: backgroundWorker.id,
inProgressRuns,
env: this.env.id,
});

const subscriber = await devPubSub.subscribe(`backgroundWorker:${backgroundWorker.id}:*`);
Expand Down Expand Up @@ -138,6 +144,7 @@ export class DevQueueConsumer {
logger.debug("[DevQueueConsumer] taskAttemptCompleted()", {
taskRunCompletion: completion,
execution,
env: this.env.id,
});

const service = new CompleteAttemptService();
Expand All @@ -151,7 +158,7 @@ export class DevQueueConsumer {
public async taskRunFailed(workerId: string, completion: TaskRunFailedExecutionResult) {
this._taskFailures++;

logger.debug("[DevQueueConsumer] taskRunFailed()", { completion });
logger.debug("[DevQueueConsumer] taskRunFailed()", { completion, env: this.env.id });

this._inProgressRuns.delete(completion.id);

Expand Down Expand Up @@ -188,7 +195,7 @@ export class DevQueueConsumer {
return;
}

logger.debug("Stopping dev queue consumer", { env: this.env });
logger.debug("[DevQueueConsumer] Stopping dev queue consumer", { env: this.env });

this._enabled = false;

Expand Down Expand Up @@ -335,6 +342,10 @@ export class DevQueueConsumer {
});

if (!existingTaskRun) {
logger.debug("Failed to find existing task run, acking", {
messageId: message.messageId,
});

await marqs?.acknowledgeMessage(message.messageId);
setTimeout(() => this.#doWork(), 100);
return;
Expand All @@ -346,6 +357,14 @@ export class DevQueueConsumer {
: this.#getLatestBackgroundWorker();

if (!backgroundWorker) {
logger.debug("Failed to find background worker, acking", {
messageId: message.messageId,
lockedToVersionId: existingTaskRun.lockedToVersionId,
deprecatedWorkers: Array.from(this._deprecatedWorkers.keys()),
backgroundWorkers: Array.from(this._backgroundWorkers.keys()),
latestWorker: this.#getLatestBackgroundWorker(),
});

await marqs?.acknowledgeMessage(message.messageId);
setTimeout(() => this.#doWork(), 100);
return;
Expand Down
68 changes: 68 additions & 0 deletions scripts/unpack-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const fs = require("fs");
const zlib = require("zlib");
const path = require("path");

// Get the file paths from command line arguments
let [jsonFilePath, destDir] = process.argv.slice(2);

if (!jsonFilePath || !destDir) {
console.error("Usage: node script.js <json-file-path> <destination-directory>");
process.exit(1);
}

// Function to decompress the content
function decompressContent(base64Encoded) {
// Decode base64 string to buffer
const compressedData = Buffer.from(base64Encoded, "base64");

// Decompress the data
const decompressedData = zlib.inflateSync(compressedData);

// Convert buffer to string
return decompressedData.toString();
}

try {
// Read and parse the JSON file
const jsonContent = fs.readFileSync(jsonFilePath, "utf8");

const data = JSON.parse(jsonContent)[0];

console.log(data);

const id = data.id;

console.log(`Extracting files for: ${id} to ${destDir}`);

destDir = path.join(destDir, id);

console.log(`Extracting files to: ${destDir}`);

// Create the destination directory if it doesn't exist
fs.mkdirSync(destDir, { recursive: true });

// Process each item in the array
const sourceFiles = data.metadata.sourceFiles;

sourceFiles.forEach((file) => {
// Decompress the contents
const decompressedContent = decompressContent(file.contents);

// Combine destination directory with file path
const fullPath = path.join(destDir, file.filePath);

// Create directory structure if it doesn't exist
const dirPath = path.dirname(fullPath);
fs.mkdirSync(dirPath, { recursive: true });

// Write the decompressed content to the file
fs.writeFileSync(fullPath, decompressedContent);

console.log(`Created file: ${fullPath}`);
});

console.log(`\nAll files have been extracted to: ${destDir}`);
} catch (error) {
console.error(error);
process.exit(1);
}
Loading