Lines 100-143
sub enqueue {
Link Here
|
100 |
|
100 |
|
101 |
my $borrowernumber = C4::Context->userenv->{number}; # FIXME Handle non GUI calls |
101 |
my $borrowernumber = C4::Context->userenv->{number}; # FIXME Handle non GUI calls |
102 |
my $json_args = encode_json $job_args; |
102 |
my $json_args = encode_json $job_args; |
103 |
my $job_id; |
103 |
$self->set( |
104 |
$self->_result->result_source->schema->txn_do( |
104 |
{ |
105 |
sub { |
105 |
status => 'new', |
106 |
$self->set( |
106 |
type => $job_type, |
107 |
{ |
107 |
size => $job_size, |
108 |
status => 'new', |
108 |
data => $json_args, |
109 |
type => $job_type, |
109 |
enqueued_on => dt_from_string, |
110 |
size => $job_size, |
110 |
borrowernumber => $borrowernumber, |
111 |
data => $json_args, |
|
|
112 |
enqueued_on => dt_from_string, |
113 |
borrowernumber => $borrowernumber, |
114 |
} |
115 |
)->store; |
116 |
|
117 |
$job_id = $self->id; |
118 |
$job_args->{job_id} = $job_id; |
119 |
$json_args = encode_json $job_args; |
120 |
|
121 |
try { |
122 |
my $conn = $self->connect; |
123 |
# This namespace is wrong, it must be a vhost instead. |
124 |
# But to do so it needs to be created on the server => much more work when a new Koha instance is created. |
125 |
# Also, here we just want the Koha instance's name, but it's not in the config... |
126 |
# Picking a random id (memcached_namespace) from the config |
127 |
my $namespace = C4::Context->config('memcached_namespace'); |
128 |
$conn->send_with_receipt( { destination => sprintf("/queue/%s-%s", $namespace, $job_type), body => $json_args } ) |
129 |
or Koha::Exception->throw('Job has not been enqueued'); |
130 |
} catch { |
131 |
if ( ref($_) eq 'Koha::Exception' ) { |
132 |
$_->rethrow; |
133 |
} else { |
134 |
warn sprintf "The job has not been sent to the message broker: (%s)", $_; |
135 |
} |
136 |
}; |
137 |
} |
111 |
} |
138 |
); |
112 |
)->store; |
|
|
113 |
|
114 |
$job_args->{job_id} = $self->id; |
115 |
$json_args = encode_json $job_args; |
116 |
|
117 |
try { |
118 |
my $conn = $self->connect; |
119 |
# This namespace is wrong, it must be a vhost instead. |
120 |
# But to do so it needs to be created on the server => much more work when a new Koha instance is created. |
121 |
# Also, here we just want the Koha instance's name, but it's not in the config... |
122 |
# Picking a random id (memcached_namespace) from the config |
123 |
my $namespace = C4::Context->config('memcached_namespace'); |
124 |
$conn->send_with_receipt( { destination => sprintf("/queue/%s-%s", $namespace, $job_type), body => $json_args } ) |
125 |
or Koha::Exceptions::Exception->throw('Job has not been enqueued'); |
126 |
} catch { |
127 |
$self->status('failed')->store; |
128 |
if ( ref($_) eq 'Koha::Exceptions::Exception' ) { |
129 |
$_->rethrow; |
130 |
} else { |
131 |
warn sprintf "The job has not been sent to the message broker: (%s)", $_; |
132 |
} |
133 |
}; |
139 |
|
134 |
|
140 |
return $job_id; |
135 |
return $self->id; |
141 |
} |
136 |
} |
142 |
|
137 |
|
143 |
=head3 process |
138 |
=head3 process |