Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering reindex of parent after updating Sub-task does not work.

henrik_gerdtsson March 29, 2022

Backgroud.
A scrum team would like to see the sum of hours estimated in Sub-tasks in the Backlog. The grey oval should contain Total Remaining Estimate. For this I created the custom field Total Remaining Estimate to be used in the configuration of the scrum board. The new custom field is populated by a scripted field that calculates the sum of remaining estimates in the Task and its Sub-tasks. This works very well.

Problem.
When work is logged in a Sub-task the Total Remaining Estimate has to be recalculated. Since the Parent is not updated it is not reindexed. I wrote a Scriptrunner listener to trigger the reindex. All fields are updated nicely, except for the number in the grey oval. It is only updated if I do a project reindex or the Task is updated, e.g. change the Description. I presume the updated triggers a reindex. When I update the Task the change in the grey oval is instant.

Is the problem with my script or is there some other process needed for the Scrum board to get the correct values.

Script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.index.IssueIndexingService

def issue = event.issue
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)

issueIndexingService.reIndex(issue)
log.warn("*** Reindex issue: ${issue.getKey()}, ${issue.getIssueType().getName()}")

if (issue.getIssueType().getName() == "Sub-task") {
  issueIndexingService.reIndex(issue.getParentObject())
  log.warn("*** Reindex parent: ${issue.getParentObject().getKey()}, ${issue.getParentObject().getIssueType().getName()}")
}

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk
Community Champion
March 29, 2022

Hi @henrik_gerdtsson 

As far as I know, you can't achieve that with listeners due to the race condition. When the subtask fires the event, your listener is triggered and the code runs immediately, however at that time subtask's indexing has not been completed yet. After all listener codes run, the subtask is indexed. So, you need to run your code after a while.

I can suggest defining an escalation service for subtasks and reindexing their parents accordingly.

henrik_gerdtsson March 30, 2022

Hello @Tuncay Senturk 

I do not understand why there would be a race condition. The listener is triggered when the Sub-task is updated, Issue Update event or Work Logged On Issue event. All data in the Sub-task should be available for the Parent when it is re-indexed.
In this I presume that the events are sent after the Sub-task is re-indexed, as in a transition. 

I tried to remove the re-indexing of the Sub-task in the Listener and only trigger the re-index of the Parent. That did not work.

I then wrote a small script in the Scriptrunner Script Console to trigger a re-index of the Parent. It works nicely. This might confirm that there is a race condition with the listener.

I will look in to the Escalation Service.

Thank you for your response

Tuncay Senturk
Community Champion
March 30, 2022

I had similar problems with post functions. You know the last step of post functions is the reindexing, but when the event listener (issue_updated event) is triggered the indexing may not be finished. Probably, it is same with your condition.

Suggest an answer

Log in or Sign up to answer