|
Lines 105-112
sub enqueue {
Link Here
|
| 105 |
|
105 |
|
| 106 |
my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef; |
106 |
my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef; |
| 107 |
$job_context->{interface} = C4::Context->interface; |
107 |
$job_context->{interface} = C4::Context->interface; |
| 108 |
my $json_context = $json->encode($job_context); |
|
|
| 109 |
my $json_args = $json->encode($job_args); |
| 110 |
|
108 |
|
| 111 |
$self->set( |
109 |
$self->set( |
| 112 |
{ |
110 |
{ |
|
Lines 114-128
sub enqueue {
Link Here
|
| 114 |
type => $job_type, |
112 |
type => $job_type, |
| 115 |
queue => $job_queue, |
113 |
queue => $job_queue, |
| 116 |
size => $job_size, |
114 |
size => $job_size, |
| 117 |
data => $json_args, |
115 |
data => $json->encode($job_args), |
| 118 |
context => $json_context, |
116 |
context => $json->encode($job_context), |
| 119 |
enqueued_on => dt_from_string, |
117 |
enqueued_on => dt_from_string, |
| 120 |
borrowernumber => $borrowernumber, |
118 |
borrowernumber => $borrowernumber, |
| 121 |
} |
119 |
} |
| 122 |
)->store; |
120 |
)->store; |
| 123 |
|
121 |
|
| 124 |
$job_args->{job_id} = $self->id; |
|
|
| 125 |
|
| 126 |
my $conn; |
122 |
my $conn; |
| 127 |
try { |
123 |
try { |
| 128 |
$conn = $self->connect; |
124 |
$conn = $self->connect; |
|
Lines 131-144
sub enqueue {
Link Here
|
| 131 |
}; |
127 |
}; |
| 132 |
return unless $conn; |
128 |
return unless $conn; |
| 133 |
|
129 |
|
| 134 |
$json_args = $json->encode($job_args); |
|
|
| 135 |
try { |
130 |
try { |
| 136 |
# This namespace is wrong, it must be a vhost instead. |
131 |
# This namespace is wrong, it must be a vhost instead. |
| 137 |
# But to do so it needs to be created on the server => much more work when a new Koha instance is created. |
132 |
# But to do so it needs to be created on the server => much more work when a new Koha instance is created. |
| 138 |
# Also, here we just want the Koha instance's name, but it's not in the config... |
133 |
# Also, here we just want the Koha instance's name, but it's not in the config... |
| 139 |
# Picking a random id (memcached_namespace) from the config |
134 |
# Picking a random id (memcached_namespace) from the config |
| 140 |
my $namespace = C4::Context->config('memcached_namespace'); |
135 |
my $namespace = C4::Context->config('memcached_namespace'); |
| 141 |
my $encoded_args = Encode::encode_utf8( $json_args ); # FIXME We should better leave this to Net::Stomp? |
136 |
my $encoded_args = Encode::encode_utf8( |
|
|
137 |
$json->encode( { job_id => $self->id } ) |
| 138 |
); # FIXME We should better leave this to Net::Stomp? |
| 142 |
$conn->send_with_receipt( { destination => sprintf("/queue/%s-%s", $namespace, $job_queue), body => $encoded_args } ) |
139 |
$conn->send_with_receipt( { destination => sprintf("/queue/%s-%s", $namespace, $job_queue), body => $encoded_args } ) |
| 143 |
or Koha::Exceptions::Exception->throw('Job has not been enqueued'); |
140 |
or Koha::Exceptions::Exception->throw('Job has not been enqueued'); |
| 144 |
} catch { |
141 |
} catch { |
|
Lines 166-172
sub process {
Link Here
|
| 166 |
|
163 |
|
| 167 |
my $derived_class = $self->_derived_class; |
164 |
my $derived_class = $self->_derived_class; |
| 168 |
|
165 |
|
| 169 |
$args ||= {}; |
166 |
$args ||= $self->json->decode($self->data); |
| 170 |
|
167 |
|
| 171 |
if ( $self->context ) { |
168 |
if ( $self->context ) { |
| 172 |
my $context = $self->json->decode($self->context); |
169 |
my $context = $self->json->decode($self->context); |
| 173 |
- |
|
|