rollaback ALL promises ? possible ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

rollaback ALL promises ? possible ?

soda
This post has NOT been accepted by the mailing list yet.

Hi,

Im using Grails' new async/promises api which is built upon Gpars as far as I know. So my question really relates to gpars I think..


Im using the new async api to parallelize some file processing/db updating.

I launch several promises which each read files, parse and then update the db. This is all sone inside a @transactional Service method.

My problem though is rolling back the work of all the promises if one of them goes wrong and throws a runtimeexception. Only the one that cause the exception does a rollback, all the others commit their work (which i dont want)

I tried promise.onError also but no luck.

Is it even possible to achieve what I am trying ? I think a new hibernate session is created for each promise if im not mistaken which would mean I cant do what Im trying to do - I think

In terms of db operations is gpars really only suitable for reads rather than writes ?


    @Transactional
    def processFiles(Date fileDate) {
        try{
        println "Starting processing at ${new Date()}"

        List<Promise> incomingFileProcessingPromises = []

        String fileDatePattern = fileDate.format(customDateFormatAccessDevelopment)
        accessDir.eachFileMatch(~/.*\.csv/) { File file ->
            String fileName = file.name
            if (fileName.contains(fileDatePattern) && fileName.contains(incoming)) {
                //execute in parallel
                incomingFileProcessingPromises << task { processXXXFile(file) }
            }

        }

        // wait for all to complete
        waitAll(incomingFileProcessingPromises)

        println "Finishing processing at ${new Date()}"

        }catch (Exception ex){
            println ex
            throw new IllegalStateException(ex)  // I thought this would roll back everything????
        }


    }