Skip to content

Commit

Permalink
Also send the progress information from the server
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Maischein committed May 26, 2024
1 parent d25da88 commit deef5eb
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions script/command-submit.pl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,30 @@ ( $self, $options )
# U
# XXX Find what item was updated from ->jobs()
# emit a 'progress' on that item
main::msg("REPLY: $line");
#main::msg("REPLY: $line");

my $r = decode_json( $line );
if( my $id = $r->{id} ) {
(my $item) = grep { $_->id eq $id } $self->jobs->@*;
if( ! $item ) {
main::msg("No item with id '$id' found?!");
main::msg(Dumper($r));
} else {
my @keys = qw(total action visual );
for( @keys ) {
$item->{$_} = $r->{$_} if exists $r->{$_};
};

if( $r->{progress_state} eq 'progressing' ) {
$item->progress( $r->{curr} );
} elsif( $r->{progress_state} eq 'finished' ) {
#main::msg("Item finished");
$item->finish()
} else {
main::msg("Unknown progress state '$r->{progress_state}'");
};
};
};

$self->emit('update');

Expand Down Expand Up @@ -245,10 +268,6 @@ ( $self, $args )
my $obj = COWS::ProgressItem->new();
my $id = Mojo::IOLoop->server( $args => sub( $loop, $stream, $id ) {
$stream->with_roles('+LineBuffer')->watch_lines->on(read_line => sub( $stream, $line, $sep) {
# XXX decode the line to JSON before emitting it
#$self->emit('line', $line );
#main::msg("Read line <<$line>>");

if( $line =~ /\A\{/ ) {
$line = decode_json( $line );
}
Expand Down Expand Up @@ -305,12 +324,14 @@ ( $self, $_job, $remote=undef )
$progress->on('finish' => sub($progress,@) {
my $j = $self->jobs;
$j->@* = grep { $_ != $progress } $j->@*;
main::msg(sprintf "Item %s done (%s)", $progress->id, $progress);
main::msg(sprintf "Jobs: " . join ", ", $j->@*);
#main::msg(sprintf "Item %s done (%s)", $progress->id, $progress);
#main::msg(sprintf "Jobs: " . join ", ", $j->@*);

if( ! $j->@* ) {
$self->emit('idle');
}
} else {
$self->emit('update');
};
});

# Fail?
Expand Down Expand Up @@ -347,13 +368,20 @@ ( $self, $job, $remote=undef )

my $want_responses = undef;

my $line = ref $job ? encode_json( { id => join( "\0", $$, $id++), notify => $want_responses, payload => $job }) : $job;
my $id = join( "\0", $$, $id++);

my $line = ref $job ? encode_json( {
id => $id, notify => $want_responses, payload => $job,
# XXX make generic
visual => $job->{visual},
}) : $job;
my $s = $self->server;

# Create a progress item and return that here!
my $item = COWS::ProgressItem->new(
total => undef,
visual => 'remote',
visual => 'waiting for remote',
id => $id,
);
push $self->jobs->@*, $item;

Expand Down Expand Up @@ -429,6 +457,7 @@ package main;
sub status($item) {
my $perc = $item->percent;
$perc = defined $perc ? sprintf "% 3d%%", $perc : ' -- ';
my $vis = $item->visual // '?';
return sprintf "%s %s %s", $perc, $item->action, $item->visual;
}

Expand Down

0 comments on commit deef5eb

Please sign in to comment.