Table of contents
  1. Example Using GPARS
  2. ASYNC




Example Using GPARS

ASYNC

 def resendRegistrationEmailAndLockUserAccount(def userList) {
    def emailsSent = []
    def emailsNotSent = []
    def nThreads = Runtime.getRuntime().availableProcessors()
    def size = (userList.size() / nThreads).intValue()
    def promises = []

    withPool nThreads, {
        userList.collate(size).each { subList ->
            def promise = task {
                subList.each { userInstance ->
                    User.withTransaction {
                        def auth0Response = sendRegistrationEmail(userInstance)
                        if (auth0Response.type == "success") {
                            emailsSent << userInstance.email
                            userInstance.inAdminResetProcess = true
                            userInstance.save(flush: true)
                            userInstance.setActive(true)
                        } else {
                            emailsNotSent << userInstance.email
                        }
                    }
                }
            }
            promises.add(promise)
        }
        waitAll(promises)
    }

    return ["emailsSent": emailsSent, "emailsNotSent": emailsNotSent]
}