Bug 30360

Summary: Add helper methods to Koha::BackgroundJobs
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: Architecture, internals, and plumbingAssignee: Tomás Cohen Arazi <tomascohen>
Status: CLOSED FIXED QA Contact: Martin Renvoize <martin.renvoize>
Severity: enhancement    
Priority: P5 - low CC: dcook, fridolin.somers, jonathan.druart, julian.maurice, kyle, martin.renvoize, tomascohen
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.05.00
Bug Depends on: 27344    
Bug Blocks: 27341, 30692, 30734, 30943, 31351    
Attachments: Bug 30360: Add helper methods to Koha::BackgroundJobs
Bug 30360: Add methods for dealing with the JSON payload
Bug 30360: Make UpdateElasticIndex use the helper methods
Bug 30360: Add helper methods to Koha::BackgroundJobs
Bug 30360: Add methods for dealing with the JSON payload
Bug 30360: Make UpdateElasticIndex use the helper methods
Bug 30360: Add helper methods to Koha::BackgroundJobs
Bug 30360: Add methods for dealing with the JSON payload
Bug 30360: Make UpdateElasticIndex use the helper methods
Bug 30360: Add helper methods to Koha::BackgroundJobs
Bug 30360: Add methods for dealing with the JSON payload
Bug 30360: Make UpdateElasticIndex use the helper methods

Description Tomás Cohen Arazi 2022-03-25 13:30:19 UTC
It would be handy to have background jobs just call a simple method for:

* Setting the job as started
* Updating the progress
* Setting as finished
Comment 1 Tomás Cohen Arazi 2022-03-25 14:55:02 UTC
Created attachment 132247 [details] [review]
Bug 30360: Add helper methods to Koha::BackgroundJobs

This patch adds some helper methods to ease writing background jobs, and
also making it more consistent/solid.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass. The methods have the expected behaviour.
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 2 Jonathan Druart 2022-03-25 15:24:29 UTC
What about retry?
Comment 3 Tomás Cohen Arazi 2022-03-25 15:46:51 UTC
(In reply to Jonathan Druart from comment #2)
> What about retry?

Yeah, I thought about it, and like the idea. It would involve (maybe) a new status which by the way we should move into an ENUM.

I left it out only because I believe we need to also think of 'all or nothing' vs 'partial success' tasks. We should support both, in my opinion.
Comment 4 Tomás Cohen Arazi 2022-04-04 22:34:14 UTC
Created attachment 132952 [details] [review]
Bug 30360: Add methods for dealing with the JSON payload

This patch adds high-level methods to handle the JSON payload
(de)serialization as needed. This allows devs implementing background
jobs to abstract themselves from the internals of the jobs handling.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 5 Tomás Cohen Arazi 2022-04-05 08:54:37 UTC
Created attachment 132953 [details] [review]
Bug 30360: Make UpdateElasticIndex use the helper methods

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 6 Martin Renvoize 2022-04-11 16:48:05 UTC
Looking forward to this one :)
Comment 7 Tomás Cohen Arazi 2022-04-29 17:59:36 UTC
Created attachment 134414 [details] [review]
Bug 30360: Add helper methods to Koha::BackgroundJobs

This patch adds some helper methods to ease writing background jobs, and
also making it more consistent/solid.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass. The methods have the expected behaviour.
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 8 Tomás Cohen Arazi 2022-04-29 17:59:41 UTC
Created attachment 134415 [details] [review]
Bug 30360: Add methods for dealing with the JSON payload

This patch adds high-level methods to handle the JSON payload
(de)serialization as needed. This allows devs implementing background
jobs to abstract themselves from the internals of the jobs handling.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 9 Tomás Cohen Arazi 2022-04-29 17:59:46 UTC
Created attachment 134416 [details] [review]
Bug 30360: Make UpdateElasticIndex use the helper methods

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 10 David Nind 2022-04-29 18:05:58 UTC
Created attachment 134417 [details] [review]
Bug 30360: Add helper methods to Koha::BackgroundJobs

This patch adds some helper methods to ease writing background jobs, and
also making it more consistent/solid.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass. The methods have the expected behaviour.
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Nind <david@davidnind.com>
Comment 11 David Nind 2022-04-29 18:06:04 UTC
Created attachment 134418 [details] [review]
Bug 30360: Add methods for dealing with the JSON payload

This patch adds high-level methods to handle the JSON payload
(de)serialization as needed. This allows devs implementing background
jobs to abstract themselves from the internals of the jobs handling.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Nind <david@davidnind.com>
Comment 12 David Nind 2022-04-29 18:06:10 UTC
Created attachment 134419 [details] [review]
Bug 30360: Make UpdateElasticIndex use the helper methods

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: David Nind <david@davidnind.com>
Comment 13 Tomás Cohen Arazi 2022-05-02 12:09:38 UTC
(In reply to David Nind from comment #11)
>
> Signed-off-by: David Nind <david@davidnind.com>

Thanks, David!!
Comment 14 Martin Renvoize 2022-05-05 10:54:33 UTC
Created attachment 134631 [details] [review]
Bug 30360: Add helper methods to Koha::BackgroundJobs

This patch adds some helper methods to ease writing background jobs, and
also making it more consistent/solid.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass. The methods have the expected behaviour.
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 15 Martin Renvoize 2022-05-05 10:54:37 UTC
Created attachment 134632 [details] [review]
Bug 30360: Add methods for dealing with the JSON payload

This patch adds high-level methods to handle the JSON payload
(de)serialization as needed. This allows devs implementing background
jobs to abstract themselves from the internals of the jobs handling.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/BackgroundJob.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 16 Martin Renvoize 2022-05-05 10:54:42 UTC
Created attachment 134633 [details] [review]
Bug 30360: Make UpdateElasticIndex use the helper methods

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 17 Martin Renvoize 2022-05-05 10:56:55 UTC
Ack, I actually QA'd this soon after David's SO and then promptly got interrupted before uploading the patches and changing the status.

It's a really solid improvement and does no harm so I'm marking it as a 22.05 candidate.
Comment 18 Martin Renvoize 2022-05-05 15:13:03 UTC
Pushed for 22.05, thanks to everyone involved :).. dependency for trivial bug 30362