Bugzilla – Attachment 107387 Details for
Bug 22417
Add a task queue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22417: Add Koha::BackgroundJob[s]
Bug-22417-Add-KohaBackgroundJobs.patch (text/plain), 2.95 KB, created by
Jonathan Druart
on 2020-07-27 07:54:14 UTC
(
hide
)
Description:
Bug 22417: Add Koha::BackgroundJob[s]
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-07-27 07:54:14 UTC
Size:
2.95 KB
patch
obsolete
>From 82beae5fb84d686c355595775e4ebd8866e1fcba Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 25 Feb 2019 21:42:43 -0300 >Subject: [PATCH] Bug 22417: Add Koha::BackgroundJob[s] > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/BackgroundJob.pm | 89 ++++++++++++++++++++++++++++++++++++++++++ > Koha/BackgroundJobs.pm | 14 +++++++ > 2 files changed, 103 insertions(+) > create mode 100644 Koha/BackgroundJob.pm > create mode 100644 Koha/BackgroundJobs.pm > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >new file mode 100644 >index 0000000000..6eab98c6b5 >--- /dev/null >+++ b/Koha/BackgroundJob.pm >@@ -0,0 +1,89 @@ >+package Koha::BackgroundJob; >+ >+use Modern::Perl; >+use JSON qw( encode_json decode_json ); >+use Carp qw( croak ); >+use C4::Context; >+use Koha::DateUtils qw( dt_from_string ); >+use Koha::BackgroundJobs; >+ >+use base qw( Koha::Object ); >+ >+sub connect { >+ my ( $self ); >+ my $conn = Net::RabbitFoot->new()->load_xml_spec()->connect( >+ host => 'localhost', # TODO Move this to KOHA_CONF >+ port => 5672, >+ user => 'guest', >+ pass => 'guest', >+ vhost => '/', >+ ); >+ >+ return $conn; >+} >+ >+sub enqueue { >+ my ( $self, $params ) = @_; >+ >+ my $job_type = $params->{job_type}; >+ my $job_size = $params->{job_size}; >+ my $job_args = $params->{job_args}; >+ >+ my $json_args = encode_json $job_args; >+ $self->set({ >+ status => 'new', >+ type => $job_type, >+ size => $job_size, >+ data => $json_args, >+ enqueued_on => dt_from_string, >+ borrowernumber => C4::Context->userenv->{id}, # FIXME Handle non GUI calls >+ })->store; >+ >+ my $job_id = $self->id; >+ $job_args->{job_id} = $job_id; >+ $json_args = encode_json $job_args, >+ >+ my $conn = $self->connect; >+ my $channel = $conn->open_channel(); >+ >+ $channel->declare_queue( >+ queue => $job_type, >+ durable => 1, >+ ); >+ >+ $channel->publish( >+ exchange => '', >+ routing_key => $job_type, # TODO Must be different? >+ body => $json_args, >+ ); >+ $conn->close; >+ return $job_id; >+} >+ >+sub process { croak "This method must be subclassed" } >+ >+sub messages { >+ my ( $self ) = @_; >+ >+ my @messages; >+ my $data_dump = decode_json $self->data; >+ if ( exists $data_dump->{messages} ) { >+ @messages = @{ $data_dump->{messages} }; >+ } >+ >+ return @messages; >+} >+ >+sub report { >+ my ( $self ) = @_; >+ >+ my $data_dump = decode_json $self->data; >+ return $data_dump->{report}; >+} >+ >+ >+sub _type { >+ return 'BackgroundJob'; >+} >+ >+1; >diff --git a/Koha/BackgroundJobs.pm b/Koha/BackgroundJobs.pm >new file mode 100644 >index 0000000000..6e44990c9e >--- /dev/null >+++ b/Koha/BackgroundJobs.pm >@@ -0,0 +1,14 @@ >+package Koha::BackgroundJobs; >+ >+use Modern::Perl; >+use base qw(Koha::Objects); >+ >+sub _type { >+ return 'BackgroundJob'; >+} >+ >+sub object_class { >+ return 'Koha::BackgroundJob'; >+} >+ >+1; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22417
:
105542
|
105543
|
107385
|
107386
|
107387
|
107388
|
107389
|
107390
|
107391
|
107392
|
107393
|
107394
|
107395
|
107396
|
107397
|
107398
|
107399
|
107400
|
107401
|
107402
|
107403
|
107404
|
107405
|
107406
|
107481
|
107482
|
107682
|
108023
|
108024
|
108025
|
108026
|
108027
|
108028
|
108029
|
108030
|
108031
|
108032
|
108033
|
108034
|
108035
|
108036
|
108037
|
108038
|
108039
|
108040
|
108041
|
108042
|
108043
|
108044
|
108045
|
108046
|
108047
|
109270
|
109271
|
109319
|
109320
|
109321
|
109322
|
109323
|
109324
|
109325
|
109326
|
109327
|
109328
|
109329
|
109330
|
109331
|
109332
|
109333
|
109334
|
109335
|
109336
|
109337
|
109338
|
109339
|
109340
|
109341
|
109342
|
109343
|
109344
|
109345
|
109350
|
109351
|
109355
|
109390
|
109391
|
109392
|
109393
|
109394
|
109395
|
109396
|
109397
|
109398
|
109399
|
109400
|
109401
|
109402
|
109403
|
109404
|
109405
|
109406
|
109407
|
109408
|
109409
|
109410
|
109411
|
109412
|
109413
|
109414
|
109415
|
109416
|
109417
|
109418
|
109474
|
109475
|
109476
|
109477
|
110150
|
111091
|
111092
|
111093
|
111094
|
111095
|
111096
|
111097
|
111098
|
111099
|
111100
|
111101
|
111102
|
111103
|
111104
|
111105
|
111106
|
111107
|
111108
|
111109
|
111110
|
111111
|
111112
|
111113
|
111114
|
111115
|
111116
|
111117
|
111118
|
111119
|
111120
|
111121
|
111238
|
111239
|
111245