Skip to content

Commit

Permalink
Properly handle local and remote jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Maischein committed May 26, 2024
1 parent deef5eb commit 76b80d4
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions script/command-submit.pl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ ( $self, $options )
});
$s->on( close => sub($stream) {
# The other side closes if it is done with our stuff
# Should we maybe simply emit 'idle' here instead?!
# or "done" ?!
$loop->stop_gracefully if $loop;
});
};
Expand Down Expand Up @@ -298,16 +300,12 @@ package MooX::JobFunnel::Worker::Server;
required => 1,
);

sub add( $self, $_job, $remote=undef ) {
my( $job, $id );
sub add( $self, $job, $remote=undef ) {
my( $id );
state $local_id;
# XXX this should maybe happen in the socket listener instead?!
if( ref $_job and $remote ) {
$job = $_job->{payload};
$id = $_job->{id};
} else {
$job = $_job;
# XXX make up a (local) id
if( ! $remote ) {
# make up a (local) id
$id = join "\0", $$, $local_id++;
};
my $progress = $self->new_job->( $job );
Expand All @@ -327,10 +325,9 @@ ( $self, $_job, $remote=undef )
#main::msg(sprintf "Item %s done (%s)", $progress->id, $progress);
#main::msg(sprintf "Jobs: " . join ", ", $j->@*);

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

Expand Down Expand Up @@ -364,11 +361,11 @@ package MooX::JobFunnel::Worker::Client;
# Should we track some kind of id so we can also get remote progress?!
sub add( $self, $job, $remote=undef ) {
# Send job to server
state $id = 1;
state $client_id = 1;

my $want_responses = undef;

my $id = join( "\0", $$, $id++);
my $id = join( "\0", $$, $client_id++);

my $line = ref $job ? encode_json( {
id => $id, notify => $want_responses, payload => $job,
Expand All @@ -390,10 +387,9 @@ ( $self, $job, $remote=undef )
my $j = $self->jobs;
$j->@* = grep { $_ != $progress } $j->@*;

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

Expand Down

0 comments on commit 76b80d4

Please sign in to comment.