In what order are Mail Handlers run?
Platform Notice: Data Center Only - This article only applies to Atlassian apps on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Question
If you have configured more than one Mail Handler you might ask yourself in which order these will be run. Especially since a matching Mail Handler will remove the email from the server once it has processed it.
Short answer
Do not expect them to run in any particular order.
Long answer
The time when a Mail Handler is run depends on:
The exact time when the handler was created/initiated
The polling interval set for the mail handler
Each Mail Handler set up have their own schedule and the countdown to the next mail polling event by that handler begins once the handler is created (note that they are executed at an interval as opposed to a specific time).
So if you create two mail handlers that both have a polling interval of 5 minutes and Handler A was created at 12:35:12 and Handler B at 12:36:28 the polling times from then on will be as follows:
12:40:12 | Handler A |
12:41:28 | Handler B |
12:45:12 | Handler A |
12:46:28 | Handler B |
...and so on.
If a mail comes in at 12:42, the first handler to look at it will be Handler A. If that email matches the criteria of Handler A, it will process it and delete it from the mail server and Handler B will never see it. If it does not match, then Handler B will scan it at 12:46:28.
(There can be exceptions to this if the scheduler is too busy. The scheduler (Caesium) has +four+ threads. If all four are busy, then new scheduled jobs are queued up until a thread becomes available.)
When Jira is restartedthe start time of the intervals will be when the handlers are initiated at startup. Since they are all started at the same the handlers in the above example will both run the same minute and second but since the startup time can differ with a few milliseconds, there is no way of telling in advance which one will be executed first after a restart and the order might be different after the next one.
If you then after restart create a third handler, Handler C, then its interval counter will start at the time the handler was created, just like with Handler A and B described above.
So while there is a pattern to the order, for all practical planning purposes no particular order should be expected.
Logging
The current order can be seen by turning on DEBUG logging for package com.atlassian.mail.incoming. The logging will go into $JIRA_HOME/log/atlassian-jira-incoming-mail.log
The current order can be seen by turning on debug logging for incoming mail.
Go to Logging and Profiling
Click Enable for either incoming or outgoing mail logging and also Enable Debugging, depending on if you are troubleshooting incoming or outgoing mail.
Alternate method: If these options are unavailable add DEBUG level for log package com.atlassian.mail.incoming
The logging will go into
$JIRA_HOME/log/atlassian-jira-incoming-mail.log
Was this helpful?