Skip to content
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

fix(core): add flag to disable the db and logs when there are errors … #27930

Merged
merged 1 commit into from
Sep 16, 2024
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
5 changes: 3 additions & 2 deletions packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ nom = '7.1.3'
regex = "1.9.1"
rayon = "1.7.0"
rkyv = { version = "0.7", features = ["validation"] }
rusqlite = { version = "0.32.1", features = ["bundled", "array", "vtab", "wasm32-wasi-vfs"] }
thiserror = "1.0.40"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
Expand All @@ -51,10 +50,12 @@ winapi = { version = "0.3", features = ["fileapi"] }
[target.'cfg(all(not(windows), not(target_family = "wasm")))'.dependencies]
mio = "0.8"

[target.'cfg(not(target_family = "wasm"))'.dependencies]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
portable-pty = { git = "https://github.com/cammisuli/wezterm", rev = "b538ee29e1e89eeb4832fb35ae095564dce34c29" }
crossterm = "0.27.0"
ignore-files = "2.1.0"
rusqlite = { version = "0.32.1", features = ["bundled", "array", "vtab", "wasm32-wasi-vfs"] }
watchexec = "3.0.1"
watchexec-events = "2.0.1"
watchexec-filterer-ignore = "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/hasher/hash-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let taskDetails: TaskDetails;

function getTaskDetails() {
// TODO: Remove when wasm supports sqlite
if (IS_WASM) {
if (process.env.NX_DISABLE_DB === 'true' || IS_WASM) {
return null;
}
if (!taskDetails) {
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function hashTasksThatDoNotDependOnOutputsOfOtherTasks(
tasksToHash[i].hash = hashes[i].value;
tasksToHash[i].hashDetails = hashes[i].details;
}
// TODO: Remove if when wasm supports sqlite
// TODO: Remove if when sqlite is always on
if (taskDetails) {
taskDetails.recordTaskDetails(
tasksToHash.map((task) => ({
Expand Down
4 changes: 3 additions & 1 deletion packages/nx/src/native/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod cache;
pub mod expand_outputs;
pub mod file_ops;
pub mod validate_outputs;

#[cfg(not(target_arch = "wasm32"))]
pub mod cache;
9 changes: 8 additions & 1 deletion packages/nx/src/native/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;

use napi::bindgen_prelude::External;
use rusqlite::Connection;

use tracing::debug;
use crate::native::machine_id::get_machine_id;

#[napi]
Expand All @@ -18,6 +18,7 @@ pub fn connect_to_nx_db(

let c = create_connection(&db_path)?;

debug!("Checking if current existing database is compatible with Nx {}", nx_version);
let db_version = c.query_row(
"SELECT value FROM metadata WHERE key='NX_VERSION'",
[],
Expand All @@ -30,13 +31,17 @@ pub fn connect_to_nx_db(
let c = match db_version {
Ok(version) if version == nx_version => c,
_ => {
debug!("Disconnecting from existing incompatible database");
c.close().map_err(|(_, error)| anyhow::Error::from(error))?;
debug!("Removing existing incompatible database");
remove_file(&db_path)?;

debug!("Creating a new connection to a new database");
create_connection(&db_path)?
}
};

debug!("Creating table for metadata");
c.execute(
"CREATE TABLE IF NOT EXISTS metadata (
key TEXT NOT NULL PRIMARY KEY,
Expand All @@ -45,6 +50,7 @@ pub fn connect_to_nx_db(
[],
)?;

debug!("Recording Nx Version: {}", nx_version);
c.execute(
"INSERT OR REPLACE INTO metadata (key, value) VALUES ('NX_VERSION', ?)",
[nx_version],
Expand All @@ -54,6 +60,7 @@ pub fn connect_to_nx_db(
}

fn create_connection(db_path: &PathBuf) -> anyhow::Result<Connection> {
debug!("Creating connection to {:?}", db_path);
let c = Connection::open(db_path).map_err(anyhow::Error::from)?;

// This allows writes at the same time as reads
Expand Down
96 changes: 42 additions & 54 deletions packages/nx/src/native/nx.wasi-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,63 +51,51 @@ const {
})

function __napi_rs_initialize_modules(__napiInstance) {
__napiInstance.exports['__napi_register__CachedResult_struct_0']?.()
__napiInstance.exports['__napi_register__NxCache_struct_1']?.()
__napiInstance.exports['__napi_register__NxCache_impl_9']?.()
__napiInstance.exports['__napi_register__expand_outputs_10']?.()
__napiInstance.exports['__napi_register__get_files_for_outputs_11']?.()
__napiInstance.exports['__napi_register__remove_12']?.()
__napiInstance.exports['__napi_register__copy_13']?.()
__napiInstance.exports['__napi_register__validate_outputs_14']?.()
__napiInstance.exports['__napi_register__get_transformable_outputs_15']?.()
__napiInstance.exports['__napi_register__hash_array_16']?.()
__napiInstance.exports['__napi_register__hash_file_17']?.()
__napiInstance.exports['__napi_register__IS_WASM_18']?.()
__napiInstance.exports['__napi_register__get_binary_target_19']?.()
__napiInstance.exports['__napi_register__ImportResult_struct_20']?.()
__napiInstance.exports['__napi_register__find_imports_21']?.()
__napiInstance.exports['__napi_register__transfer_project_graph_22']?.()
__napiInstance.exports['__napi_register__ExternalNode_struct_23']?.()
__napiInstance.exports['__napi_register__Target_struct_24']?.()
__napiInstance.exports['__napi_register__Project_struct_25']?.()
__napiInstance.exports['__napi_register__ProjectGraph_struct_26']?.()
__napiInstance.exports['__napi_register__HashedTask_struct_27']?.()
__napiInstance.exports['__napi_register__TaskDetails_struct_28']?.()
__napiInstance.exports['__napi_register__TaskDetails_impl_31']?.()
__napiInstance.exports['__napi_register__HashPlanner_struct_32']?.()
__napiInstance.exports['__napi_register__HashPlanner_impl_36']?.()
__napiInstance.exports['__napi_register__HashDetails_struct_37']?.()
__napiInstance.exports['__napi_register__HasherOptions_struct_38']?.()
__napiInstance.exports['__napi_register__TaskHasher_struct_39']?.()
__napiInstance.exports['__napi_register__TaskHasher_impl_42']?.()
__napiInstance.exports['__napi_register__TaskRun_struct_43']?.()
__napiInstance.exports['__napi_register__NxTaskHistory_struct_44']?.()
__napiInstance.exports['__napi_register__NxTaskHistory_impl_48']?.()
__napiInstance.exports['__napi_register__Task_struct_49']?.()
__napiInstance.exports['__napi_register__TaskTarget_struct_50']?.()
__napiInstance.exports['__napi_register__TaskGraph_struct_51']?.()
__napiInstance.exports['__napi_register__FileData_struct_52']?.()
__napiInstance.exports['__napi_register__InputsInput_struct_53']?.()
__napiInstance.exports['__napi_register__FileSetInput_struct_54']?.()
__napiInstance.exports['__napi_register__RuntimeInput_struct_55']?.()
__napiInstance.exports['__napi_register__EnvironmentInput_struct_56']?.()
__napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_57']?.()
__napiInstance.exports['__napi_register__DepsOutputsInput_struct_58']?.()
__napiInstance.exports['__napi_register__NxJson_struct_59']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_60']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_69']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_70']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_71']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_72']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_73']?.()
__napiInstance.exports['__napi_register__FileMap_struct_74']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_75']?.()
__napiInstance.exports['__napi_register__expand_outputs_0']?.()
__napiInstance.exports['__napi_register__get_files_for_outputs_1']?.()
__napiInstance.exports['__napi_register__remove_2']?.()
__napiInstance.exports['__napi_register__copy_3']?.()
__napiInstance.exports['__napi_register__validate_outputs_4']?.()
__napiInstance.exports['__napi_register__get_transformable_outputs_5']?.()
__napiInstance.exports['__napi_register__hash_array_6']?.()
__napiInstance.exports['__napi_register__hash_file_7']?.()
__napiInstance.exports['__napi_register__IS_WASM_8']?.()
__napiInstance.exports['__napi_register__get_binary_target_9']?.()
__napiInstance.exports['__napi_register__ImportResult_struct_10']?.()
__napiInstance.exports['__napi_register__find_imports_11']?.()
__napiInstance.exports['__napi_register__transfer_project_graph_12']?.()
__napiInstance.exports['__napi_register__ExternalNode_struct_13']?.()
__napiInstance.exports['__napi_register__Target_struct_14']?.()
__napiInstance.exports['__napi_register__Project_struct_15']?.()
__napiInstance.exports['__napi_register__ProjectGraph_struct_16']?.()
__napiInstance.exports['__napi_register__HashPlanner_struct_17']?.()
__napiInstance.exports['__napi_register__HashPlanner_impl_21']?.()
__napiInstance.exports['__napi_register__HashDetails_struct_22']?.()
__napiInstance.exports['__napi_register__HasherOptions_struct_23']?.()
__napiInstance.exports['__napi_register__TaskHasher_struct_24']?.()
__napiInstance.exports['__napi_register__TaskHasher_impl_27']?.()
__napiInstance.exports['__napi_register__Task_struct_28']?.()
__napiInstance.exports['__napi_register__TaskTarget_struct_29']?.()
__napiInstance.exports['__napi_register__TaskGraph_struct_30']?.()
__napiInstance.exports['__napi_register__FileData_struct_31']?.()
__napiInstance.exports['__napi_register__InputsInput_struct_32']?.()
__napiInstance.exports['__napi_register__FileSetInput_struct_33']?.()
__napiInstance.exports['__napi_register__RuntimeInput_struct_34']?.()
__napiInstance.exports['__napi_register__EnvironmentInput_struct_35']?.()
__napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_36']?.()
__napiInstance.exports['__napi_register__DepsOutputsInput_struct_37']?.()
__napiInstance.exports['__napi_register__NxJson_struct_38']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_39']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_48']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_49']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_50']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_51']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_52']?.()
__napiInstance.exports['__napi_register__FileMap_struct_53']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_54']?.()
}
export const HashPlanner = __napiModule.exports.HashPlanner
export const ImportResult = __napiModule.exports.ImportResult
export const NxCache = __napiModule.exports.NxCache
export const NxTaskHistory = __napiModule.exports.NxTaskHistory
export const TaskDetails = __napiModule.exports.TaskDetails
export const TaskHasher = __napiModule.exports.TaskHasher
export const WorkspaceContext = __napiModule.exports.WorkspaceContext
export const copy = __napiModule.exports.copy
Expand Down
96 changes: 42 additions & 54 deletions packages/nx/src/native/nx.wasi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,63 +82,51 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
})

function __napi_rs_initialize_modules(__napiInstance) {
__napiInstance.exports['__napi_register__CachedResult_struct_0']?.()
__napiInstance.exports['__napi_register__NxCache_struct_1']?.()
__napiInstance.exports['__napi_register__NxCache_impl_9']?.()
__napiInstance.exports['__napi_register__expand_outputs_10']?.()
__napiInstance.exports['__napi_register__get_files_for_outputs_11']?.()
__napiInstance.exports['__napi_register__remove_12']?.()
__napiInstance.exports['__napi_register__copy_13']?.()
__napiInstance.exports['__napi_register__validate_outputs_14']?.()
__napiInstance.exports['__napi_register__get_transformable_outputs_15']?.()
__napiInstance.exports['__napi_register__hash_array_16']?.()
__napiInstance.exports['__napi_register__hash_file_17']?.()
__napiInstance.exports['__napi_register__IS_WASM_18']?.()
__napiInstance.exports['__napi_register__get_binary_target_19']?.()
__napiInstance.exports['__napi_register__ImportResult_struct_20']?.()
__napiInstance.exports['__napi_register__find_imports_21']?.()
__napiInstance.exports['__napi_register__transfer_project_graph_22']?.()
__napiInstance.exports['__napi_register__ExternalNode_struct_23']?.()
__napiInstance.exports['__napi_register__Target_struct_24']?.()
__napiInstance.exports['__napi_register__Project_struct_25']?.()
__napiInstance.exports['__napi_register__ProjectGraph_struct_26']?.()
__napiInstance.exports['__napi_register__HashedTask_struct_27']?.()
__napiInstance.exports['__napi_register__TaskDetails_struct_28']?.()
__napiInstance.exports['__napi_register__TaskDetails_impl_31']?.()
__napiInstance.exports['__napi_register__HashPlanner_struct_32']?.()
__napiInstance.exports['__napi_register__HashPlanner_impl_36']?.()
__napiInstance.exports['__napi_register__HashDetails_struct_37']?.()
__napiInstance.exports['__napi_register__HasherOptions_struct_38']?.()
__napiInstance.exports['__napi_register__TaskHasher_struct_39']?.()
__napiInstance.exports['__napi_register__TaskHasher_impl_42']?.()
__napiInstance.exports['__napi_register__TaskRun_struct_43']?.()
__napiInstance.exports['__napi_register__NxTaskHistory_struct_44']?.()
__napiInstance.exports['__napi_register__NxTaskHistory_impl_48']?.()
__napiInstance.exports['__napi_register__Task_struct_49']?.()
__napiInstance.exports['__napi_register__TaskTarget_struct_50']?.()
__napiInstance.exports['__napi_register__TaskGraph_struct_51']?.()
__napiInstance.exports['__napi_register__FileData_struct_52']?.()
__napiInstance.exports['__napi_register__InputsInput_struct_53']?.()
__napiInstance.exports['__napi_register__FileSetInput_struct_54']?.()
__napiInstance.exports['__napi_register__RuntimeInput_struct_55']?.()
__napiInstance.exports['__napi_register__EnvironmentInput_struct_56']?.()
__napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_57']?.()
__napiInstance.exports['__napi_register__DepsOutputsInput_struct_58']?.()
__napiInstance.exports['__napi_register__NxJson_struct_59']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_60']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_69']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_70']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_71']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_72']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_73']?.()
__napiInstance.exports['__napi_register__FileMap_struct_74']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_75']?.()
__napiInstance.exports['__napi_register__expand_outputs_0']?.()
__napiInstance.exports['__napi_register__get_files_for_outputs_1']?.()
__napiInstance.exports['__napi_register__remove_2']?.()
__napiInstance.exports['__napi_register__copy_3']?.()
__napiInstance.exports['__napi_register__validate_outputs_4']?.()
__napiInstance.exports['__napi_register__get_transformable_outputs_5']?.()
__napiInstance.exports['__napi_register__hash_array_6']?.()
__napiInstance.exports['__napi_register__hash_file_7']?.()
__napiInstance.exports['__napi_register__IS_WASM_8']?.()
__napiInstance.exports['__napi_register__get_binary_target_9']?.()
__napiInstance.exports['__napi_register__ImportResult_struct_10']?.()
__napiInstance.exports['__napi_register__find_imports_11']?.()
__napiInstance.exports['__napi_register__transfer_project_graph_12']?.()
__napiInstance.exports['__napi_register__ExternalNode_struct_13']?.()
__napiInstance.exports['__napi_register__Target_struct_14']?.()
__napiInstance.exports['__napi_register__Project_struct_15']?.()
__napiInstance.exports['__napi_register__ProjectGraph_struct_16']?.()
__napiInstance.exports['__napi_register__HashPlanner_struct_17']?.()
__napiInstance.exports['__napi_register__HashPlanner_impl_21']?.()
__napiInstance.exports['__napi_register__HashDetails_struct_22']?.()
__napiInstance.exports['__napi_register__HasherOptions_struct_23']?.()
__napiInstance.exports['__napi_register__TaskHasher_struct_24']?.()
__napiInstance.exports['__napi_register__TaskHasher_impl_27']?.()
__napiInstance.exports['__napi_register__Task_struct_28']?.()
__napiInstance.exports['__napi_register__TaskTarget_struct_29']?.()
__napiInstance.exports['__napi_register__TaskGraph_struct_30']?.()
__napiInstance.exports['__napi_register__FileData_struct_31']?.()
__napiInstance.exports['__napi_register__InputsInput_struct_32']?.()
__napiInstance.exports['__napi_register__FileSetInput_struct_33']?.()
__napiInstance.exports['__napi_register__RuntimeInput_struct_34']?.()
__napiInstance.exports['__napi_register__EnvironmentInput_struct_35']?.()
__napiInstance.exports['__napi_register__ExternalDependenciesInput_struct_36']?.()
__napiInstance.exports['__napi_register__DepsOutputsInput_struct_37']?.()
__napiInstance.exports['__napi_register__NxJson_struct_38']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_struct_39']?.()
__napiInstance.exports['__napi_register__WorkspaceContext_impl_48']?.()
__napiInstance.exports['__napi_register__WorkspaceErrors_49']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_50']?.()
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_51']?.()
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_52']?.()
__napiInstance.exports['__napi_register__FileMap_struct_53']?.()
__napiInstance.exports['__napi_register____test_only_transfer_file_map_54']?.()
}
module.exports.HashPlanner = __napiModule.exports.HashPlanner
module.exports.ImportResult = __napiModule.exports.ImportResult
module.exports.NxCache = __napiModule.exports.NxCache
module.exports.NxTaskHistory = __napiModule.exports.NxTaskHistory
module.exports.TaskDetails = __napiModule.exports.TaskDetails
module.exports.TaskHasher = __napiModule.exports.TaskHasher
module.exports.WorkspaceContext = __napiModule.exports.WorkspaceContext
module.exports.copy = __napiModule.exports.copy
Expand Down
7 changes: 5 additions & 2 deletions packages/nx/src/native/tasks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
mod dep_outputs;
pub mod details;
mod hash_planner;
pub mod hashers;
mod inputs;
pub mod task_hasher;
pub mod task_history;
pub mod types;
mod utils;

#[cfg(not(target_arch = "wasm32"))]
pub mod details;
#[cfg(not(target_arch = "wasm32"))]
pub mod task_history;
3 changes: 2 additions & 1 deletion packages/nx/src/tasks-runner/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export type CachedResult = {
export type TaskWithCachedResult = { task: Task; cachedResult: CachedResult };

export function getCache(options: DefaultTasksRunnerOptions) {
return process.env.NX_DB_CACHE === 'true'
return process.env.NX_DISABLE_DB !== 'true' &&
process.env.NX_DB_CACHE === 'true'
? new DbCache({
// Remove this in Nx 21
nxCloudRemoteCache: isNxCloudUsed(readNxJson())
Expand Down
4 changes: 3 additions & 1 deletion packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,9 @@ function constructLifeCycles(lifeCycle: LifeCycle) {
}
if (!isNxCloudUsed(readNxJson())) {
lifeCycles.push(
!IS_WASM ? new TaskHistoryLifeCycle() : new LegacyTaskHistoryLifeCycle()
process.env.NX_DISABLE_DB !== 'true' && !IS_WASM
? new TaskHistoryLifeCycle()
: new LegacyTaskHistoryLifeCycle()
);
}
return lifeCycles;
Expand Down
14 changes: 9 additions & 5 deletions packages/nx/src/tasks-runner/tasks-schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ export class TasksSchedule {
private notScheduledTaskGraph = this.taskGraph;
private reverseTaskDeps = calculateReverseDeps(this.taskGraph);
private reverseProjectGraph = reverse(this.projectGraph);
private taskHistory: TaskHistory = getTaskHistory();
private taskHistory: TaskHistory =
process.env.NX_DISABLE_DB !== 'true' ? getTaskHistory() : null;

private scheduledBatches: Batch[] = [];
private scheduledTasks: string[] = [];
private runningTasks = new Set<string>();
private completedTasks = new Set<string>();
private scheduleRequestsExecutionChain = Promise.resolve();
private estimatedTaskTimings: Record<string, number>;
private estimatedTaskTimings: Record<string, number> = {};

constructor(
private readonly projectGraph: ProjectGraph,
Expand All @@ -36,9 +37,12 @@ export class TasksSchedule {
) {}

public async init() {
this.estimatedTaskTimings = await this.taskHistory.getEstimatedTaskTimings(
Object.values(this.taskGraph.tasks).map((t) => t.target)
);
if (this.taskHistory) {
this.estimatedTaskTimings =
await this.taskHistory.getEstimatedTaskTimings(
Object.values(this.taskGraph.tasks).map((t) => t.target)
);
}
}

public async scheduleNextTasks() {
Expand Down