Deactivating idle users after custom period script is not finding all idle users

Hey all, I am trying to use this script to deactivate all users after 365 days:

I have updated numOfDays to 365, but the script only found users up to a certain username alphabetically. It stopped somewhere in the 'E’s. I cannot get it to find anymore idle users, despite confirming there are still plenty of ‘active’ idle users.

Not sure if this is relevant, but each time a ran the script (had to run it 4-5 times for it to deactivate users A-E alphabetically) it deactivated less and less users each time. The first run was around 450 users, and it got exponentially smaller after that (i.e. run 1: deactivated 450 users, run 2: deactivated 90 users, run 3: deactivated 15 users, run 4: deactivated 1 user.

Any help would be greatly appreciated.

Hi Ava,
according to the class definition:UserSearchService (Atlassian JIRA 7.1.9 API)

If the users in the database change during this call results might not be consistent if a post processing filter and a result limit is used.

I don’t see any limits set in the script. My test env jira does not have that many users.
My console run returns all 256 users. But to speed up execution I’ve removed call to a function deactivateUser().

Once I’ve had similar experience with script runner console. It was hanging on processing bulk data. I think it was Issue.Update. I’ve ended up feeding list of issue id’s to the script in batched chunks via file system.
Have you checked Jira log? Is there any warning on execution termination and timeouts?