Skip to content

Commit

Permalink
fix: optionally use log dir path; create if not exist
Browse files Browse the repository at this point in the history
fix: longer sleep period when no job is enqueued
  • Loading branch information
williams-jack committed Aug 14, 2024
1 parent 22eefe4 commit 397dec1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
4 changes: 3 additions & 1 deletion orchestrator/packages/common/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface OrchestratorConfig {
dockerImageFolder: string;
postgresURL: string;
environment: string;
orchestratorLogsDir?: string;
}

interface OrchestratorAPIOptions {
Expand All @@ -17,5 +18,6 @@ export const getConfig = (): OrchestratorConfig => ({
port: process.env.API_PORT ? parseInt(process.env.API_PORT) : 8090,
},
dockerImageFolder: join(__dirname, "../../../", "images"),
environment: process.env.ENVIRONMENT?.toLowerCase() || 'dev'
environment: process.env.ENVIRONMENT?.toLowerCase() || 'dev',
orchestratorLogsDir: process.env.ORCHESTRATOR_LOG_DIR
});
39 changes: 24 additions & 15 deletions orchestrator/packages/common/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import pino from "pino";
import { getConfig } from "./config";
import path from "path";
import { existsSync, mkdirSync } from "fs";

const _CONFIG = getConfig();

const pinoTarget = {
target: 'pino/file',
options: {
destination: _CONFIG.orchestratorLogsDir ?
path.join(_CONFIG.orchestratorLogsDir, `${_CONFIG.environment}.log`) :
1 // used by pino for STDOUT
}
}

const transport = pino.transport({
targets: [
{
target: 'pino/file',
options: {
destination: path.join(__dirname, '../../../', 'logs', `${getConfig().environment}.log`),
mkdir: true
}
},
{
target: 'pino/file',
options: { destination: 2 }
}
pinoTarget
]
});

const logger = pino({
level: getConfig().environment === 'production' ? 'info' : 'debug',
timestamp: true,
}, transport);
const getLogger = () => {
if (_CONFIG.orchestratorLogsDir && !existsSync(_CONFIG.orchestratorLogsDir)) {
mkdirSync(_CONFIG.orchestratorLogsDir);
}
return pino({
level: getConfig().environment === 'production' ? 'info' : 'debug',
timestamp: true,
}, transport)
}

const logger = getLogger();

export default logger;
6 changes: 4 additions & 2 deletions worker/orca_grader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

CONTAINER_WORKING_DIR = '/home/orca-grader'
_LOGGER = logging.getLogger(__name__)
_SLEEP_LENGTH = 5 # seconds


def run_local_job(job_path: str, no_container: bool,
Expand Down Expand Up @@ -65,11 +66,12 @@ def process_jobs_from_db(no_container: bool,
if job_retrieval_future in done:
if job_retrieval_future.exception():
_LOGGER.exception("Failed to retrieve grading job from postgres.")
time.sleep(1)
time.sleep(_SLEEP_LENGTH)
continue
grading_job = job_retrieval_future.result()
if grading_job is None:
time.sleep(1)
_LOGGER.debug(f"No jobs on the queue; sleeping for {_SLEEP_LENGTH} seconds.")
time.sleep(_SLEEP_LENGTH)
continue

if stop_future in done:
Expand Down

0 comments on commit 397dec1

Please sign in to comment.