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

Support writing progress as JSON #614

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

anmenaga
Copy link
Collaborator

@anmenaga anmenaga commented Dec 12, 2024

PR Summary

Fix #592

  1. This adds writing json progress messages to STDERR stream if -f, --format argument to dsc.exe is json or pretty-json.
  2. Fixed a bug with Searching for adapted resources progress which previously was always showing 0.

The structure of json progress message is following. activity and percent_complete are expected to always have value; the rest of the fields are optional.
Same structure will be expected from resources when they will want to provide progress status to dsc (this support will be implemented soon).

pub struct DscProgressValue {
    pub activity:  String,
    pub status: String,
    pub percent_complete: u16,
    pub seconds_remaining: u64,
}

Dev notes:

  1. Added struct DscProgressBar which is wrapping both UI progress bar and json serialization;
  2. moved pub enum OutputFormat from dsc to dsc_lib and updated all references.

@anmenaga anmenaga marked this pull request as draft December 12, 2024 20:11
@anmenaga anmenaga marked this pull request as ready for review December 12, 2024 22:53
}
};

let mut configurator = match Configurator::new(&json_string) {
let mut configurator = match Configurator::new(&json_string, output_format.as_ref()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having output_format as a parameter to the constructor. Would prefer adding a set_output_format() function instead. Alternatively since this is something used all over the place, maybe put into thread local storage and just retrieve from there instead of passing it around particularly since it shouldn't change during runtime.

$LASTEXITCODE | Should -Be 0
$lines = Get-Content $TestDrive/ErrorStream.txt
$ProgressMessagesFound = $False
foreach ($line in $lines) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of comparing text, since all output should be JSON, you should convert every line from json and check the object

$lines = Get-Content $TestDrive/ErrorStream.txt
$ProgressMessagesFound = $False
foreach ($line in $lines) {
if ($line.Contains("activity")) { # if line is a progress message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, use convertfrom-json

json: String,
config: Configuration,
pub context: Context,
discovery: Discovery,
statement_parser: Statement,
progress_format: Option<&'a OutputFormat>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this as an Option, I think it should just be OutputFormat and you have the constructor set a default. This should also remove the need for lifetime.

@@ -24,6 +37,88 @@ impl Default for DscSettingValue {
}
}

#[derive(Default, Debug, Clone, Serialize)]
pub struct DscProgressValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the struct should just be called Progress

pub seconds_remaining: u64,
}

pub struct DscProgressBar {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be ProgressBar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support writing progress as JSON
2 participants