Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to cancel jobs, redo existing large images, and not force jobs #1586

Merged
merged 7 commits into from
Aug 6, 2024

Conversation

gabrielle6249
Copy link
Contributor

This adds two more options from #1139 to the PUT large_image/folder/{id}/tiles endpoint, and allows the createJobs filter to accept three states. The first flag allows cancelling unfinished large image jobs related to items in the folder, so the large image can then be removed and a new one created. The second gives the option to remove and redo existing large images in the folder. The three states createJobs now accepts can either never use a job, use one only if needed, or force one for every large image.

@gabrielle6249 gabrielle6249 marked this pull request as ready for review July 24, 2024 13:33
Copy link

@marySalvi marySalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I have a few thoughts on simplifying things but will defer to @manthey

Comment on lines 456 to 460
.param('createJobs', 'Whether job(s) should be used to create each '
'large image. Select true to use a job if needed, false to '
'never use a job, and always to always use a job.',
required=False, default='false', dataType='string',
enum=['true', 'false', 'always'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @manthey 's description in #1139 I get the impression this should be split into two options.
ie 'force' for always and 'localJob' making both boolean as seen here:

.param('force', 'Always use a job to create the large image.',
dataType='boolean', default=False, required=False)
.param('notify', 'If a job is required to create the large image, '
'a nofication can be sent when it is complete.',
dataType='boolean', default=True, required=False)
.param('localJob', 'If true, run as a local job; if false, run via '
'the remote worker', dataType='boolean', required=False)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint's previous iteration had separate 'force' and 'localJobs' parameters, then createJobs would be set to either True or 'always' internally, as seen below. We still might not want to create jobs at all, so @manthey suggested the endpoint's parameter accept a third state. The string to boolean conversion is not my favorite, though.

createJobs = 'always' if self.boolParam('force', params, default=False) else True

default=False, dataType='boolean')
.param('recurse', 'Whether child folders should be recursed.', required=False,
default=False, dataType='boolean')
.param('recurse', 'Whether child folders should be recursed.',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer definitions not to include the option unless very self-explanatory. Perhaps something like:
'If true, images in child folders will also be checked'

Also as a personal preference I would change the descriptions from 'Whether...' to 'If...'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That reads clearer and explaining what happens depending on what the user selects is a good idea. Change made here.

recurse=params.get('recurse'), createJobs=createJobs,
localJobs=params.get('localJobs'),
cancelJobs=params.get('cancelJobs'),
redo=params.get('redoExisting'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think breaking the options apart as suggested above would allow you to simplify this.

Comment on lines 485 to 501

def createLargeImagesRecurse(
self, folder, user, recurse, createJobs, localJobs, cancelJobs, redo):
result = {'childFoldersRecursed': 0,
'itemsSkipped': 0,
'jobsCanceled': 0,
'jobsFailedToCancel': 0,
'largeImagesCreated': 0,
'largeImagesRemovedAndRecreated': 0,
'totalItems': 0}
if recurse:
for childFolder in Folder().childFolders(parent=folder, parentType='folder'):
result['childFoldersRecursed'] += 1
childResult = self.createImagesRecurseOption(folder=childFolder,
createJobs=createJobs, user=user,
recurse=recurse, localJobs=localJobs)
childResult = self.createLargeImagesRecurse(folder=childFolder, user=user,
recurse=recurse, createJobs=createJobs,
localJobs=localJobs,
cancelJobs=cancelJobs, redo=redo)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels logically backwards to me. I think I would expect:

def createLargeImage(self, folder):
    for item in folder:
        ***createImage logic here***
 
def folderRecurse(self, params):
     if recurse:
        for childFolder in folder:
           createLargeImage()

additionally I am not sure I would make a new function to check the recurse param. That is a design choice for you and David to decide though.

@manthey manthey merged commit 0d2b1ee into master Aug 6, 2024
16 checks passed
@manthey manthey deleted the cancel-pending-jobs branch August 6, 2024 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants