Adding new tasks to a comment

Hi,

I am adding multiple tasks through the TaskService to comments added via the CommentService, triggered when a pull request is opened.

I add around 10 tasks right now as a test. Is there a way I can preserve the ordering of the tasks on the page? When I add them all and look at the table in the H2 database, they all have the same CREATED_TIMESTAMP as the millisecond value isn’t being preserved.

I would think that in that case the ID should take precedence (oldest first) but that seems to not be the case.

Is there a way to fix this outside of throttling the calls to the service (very hesitant as this would be 10+ seconds just to execute the code).

Thanks,
Mike

1 Like

Perhaps use ScheduledExecutorService to create a separate thread and reschedule execution for as many tasks you need to add. The main thread (event listener) would return immediately.

@michaelhum - I have a different problem - and perhaps you have a solution already. How would you find the pull request that belongs to a given task? I’m listening to TaskUpdatedEvent and need to identify the pull request that the task belongs to. I’m a bit lost as to what info in the TaskAnchor will get me to the pull request.

Thanks @izymesdev, I’ll give that a try.

I’m actually not sure about how to get the pull request. I haven’t tried it myself, but the task’s getAnchor().getId() should be the comment id it is attached to. After that, you can get the comment (from the CommentService and then maybe getThread().getCommentable() will be able to narrow it down for you.

Depending on where the comment was made, that should either be the PullRequest itself (top level comment), or you might have to go looking a bit deeper as it may be the commit the comment was made on.

Seems very round-about to be able to get the pull request, but good luck!

1 Like

Thanks @michaelhum - getting the thread and the commentable leads to the pull request. See Associating task (anchor) with Pull Request - #2 by khughes for a related post