Skip to content

Commit

Permalink
refactor: Remove logging streaming from CLI (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar authored Dec 15, 2023
1 parent 3d8a439 commit 3e86f9d
Showing 1 changed file with 81 additions and 81 deletions.
162 changes: 81 additions & 81 deletions packages/globe_cli/lib/src/commands/deploy_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:mason_logger/mason_logger.dart';
import '../command.dart';
import '../utils/api.dart';
import '../utils/archiver.dart';
import '../utils/logs.dart';
import '../utils/prompts.dart';

/// `globe deploy`
Expand Down Expand Up @@ -73,86 +72,87 @@ class DeployCommand extends BaseGlobeCommand {
'🔍 View deployment: ${metadata.endpoint}/${validated.organization.slug}/${validated.project.slug}/deployments/${deployment.id}',
);

var status = logger.progress(deployment.state.message);
final completer = Completer<void>();
Stream<BuildLogEvent>? logs;

// Check the deployment status every x seconds.
Timer.periodic(const Duration(milliseconds: 2000), (timer) async {
final update = await api.getDeployment(
orgId: validated.organization.id,
projectId: validated.project.id,
deploymentId: deployment.id,
);

if (update.state == DeploymentState.working ||
update.state == DeploymentState.deploying) {
if (logs != null) return;

status.complete();
status = logger.progress('Preparing build environment');

logs = await streamBuildLogs(
api: api,
orgId: validated.organization.id,
projectId: validated.project.id,
deploymentId: deployment.id,
);

unawaited(
logs!
.firstWhere((element) => element is! UnknownBuildLogEvent)
.then((_) => status.complete()),
);

unawaited(
logs!.firstWhere((element) {
if (element case LogsBuildLogEvent(done: final done)) return done;
return false;
}).then((_) {
status = logger.progress('Deploying...');
}),
);

unawaited(printLogs(logger, logs!));
}

if (update.state == DeploymentState.success) {
status.complete();
logger.info(
'${lightGreen.wrap('✓')} Preview: https://${update.url}',
);
}

if (update.state == DeploymentState.error) {
var message = 'Deployment failed';
if (update.message.isNotEmpty) {
message = '$message: ${update.message}';
}
status.fail(message);
}

if (update.state == DeploymentState.cancelled) {
status.complete();
logger.info('Deployment cancelled');
}

if (update.state == DeploymentState.invalid) {
status.complete();
status = logger.progress(
'Invalid Deployment State Received. Waiting for valid state',
);
}

if (update.state == DeploymentState.success ||
update.state == DeploymentState.cancelled ||
update.state == DeploymentState.error) {
timer.cancel();
completer.complete();
}
});

await completer.future;
// TODO: handle deployment logs - they currently disconnect immediately
// var status = logger.progress(deployment.state.message);
// final completer = Completer<void>();
// Stream<BuildLogEvent>? logs;

// // Check the deployment status every x seconds.
// Timer.periodic(const Duration(milliseconds: 2000), (timer) async {
// final update = await api.getDeployment(
// orgId: validated.organization.id,
// projectId: validated.project.id,
// deploymentId: deployment.id,
// );

// if (update.state == DeploymentState.working ||
// update.state == DeploymentState.deploying) {
// if (logs != null) return;

// status.complete();
// status = logger.progress('Preparing build environment');

// logs = await streamBuildLogs(
// api: api,
// orgId: validated.organization.id,
// projectId: validated.project.id,
// deploymentId: deployment.id,
// );

// unawaited(
// logs!
// .firstWhere((element) => element is! UnknownBuildLogEvent)
// .then((_) => status.complete()),
// );

// unawaited(
// logs!.firstWhere((element) {
// if (element case LogsBuildLogEvent(done: final done)) return done;
// return false;
// }).then((_) {
// status = logger.progress('Deploying...');
// }),
// );

// unawaited(printLogs(logger, logs!));
// }

// if (update.state == DeploymentState.success) {
// status.complete();
// logger.info(
// '${lightGreen.wrap('✓')} Preview: https://${update.url}',
// );
// }

// if (update.state == DeploymentState.error) {
// var message = 'Deployment failed';
// if (update.message.isNotEmpty) {
// message = '$message: ${update.message}';
// }
// status.fail(message);
// }

// if (update.state == DeploymentState.cancelled) {
// status.complete();
// logger.info('Deployment cancelled');
// }

// if (update.state == DeploymentState.invalid) {
// status.complete();
// status = logger.progress(
// 'Invalid Deployment State Received. Waiting for valid state',
// );
// }

// if (update.state == DeploymentState.success ||
// update.state == DeploymentState.cancelled ||
// update.state == DeploymentState.error) {
// timer.cancel();
// completer.complete();
// }
// });

// await completer.future;

return ExitCode.success.code;
} on ApiException catch (e) {
Expand Down

0 comments on commit 3e86f9d

Please sign in to comment.