4 Replies Latest reply on Feb 6, 2008 10:33 AM by kodemonki

    Background Processes

    kodemonki Level 1
      I have a form that requires a user to input about 40 datapoints. Once they submit the form, the 40 datapoints are inserted into our database, calculations are run on the data, and more data is inserted in the database. When all the data is in, an email is sent to the user and then the page reloaded with the entered data pre-filled in.

      Is there any way to, once they submit the data, have all the insertions and calculations and emailing go on in a seperate process while they move on and do other things? Obviously scheduled tasks are done in the background, but they are using a different session.

      Could I do a cflocation then then cfmodule and call the data submission template?

      Ideas are welcome, thanks!
        • 1. Re: Background Processes
          paross1 Level 2
          I do something similar to this all the time on my application that uses Oracle. You could have the gui prompt the user to submit the 40 datapoints via forms, etc., and populate a table in the database with the data and a status of 'submitted' etc. Then, I would have a background process (stored procedure, etc.) that runs every 'x' minutes which scans for work to do by looking for the submitted status. The stored procedure would then perform whatever activity that you wish on the pending jobs, then end by setting the job status to 'complete', or 'error', or whatever you want to use to track completed or failed jobs. Your client can then check to see if his or her job completed by accessing a page that check the status of the submitted job, etc. Works great, especially if you have process that take too long to hold up a web page.

          Phil
          • 2. Re: Background Processes
            Mr Black Level 1
            Pure server-side:
            ============
            1. Receive form.
            2. Execute CFHTTP with form fields using timeout 0 to "background" template. Ignore timeout error.
            3. Continue (redirect, if you wish)

            Client-side (may vary, but this is an idea):
            =============================
            1. Create invisible frame.
            2. When user hit "Submit" use JScript to grab parameters and submit 2 forms: one for background, another to continue.
            • 3. Re: Background Processes
              Level 7
              > Obviously scheduled tasks are
              > done in the background, but they are using a different session. Could I do a
              > cflocation then then cfmodule and call the data submission template? Ideas are
              > welcome, thanks!

              Crikey. Nothing as complicated as all that.

              Just use CFTHREAD:

              http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_t_04.html

              (or on pre-CF8, use the async gateway).

              --
              Adam
              • 4. Re: Background Processes
                kodemonki Level 1
                Thank you everyone!

                I think Adam's answer makes the most sense, especially since paross' idea was shot down when I suggested it to my boss a few days ago, but I'm glad I got that because it's always good to know your ideas are shared by people more knowledgeable that yourself.

                I've done a little research and found cfthread to be exceptional, but I haven't found a way to do inline code. It works really well when a template is called though. I don't even know if it can do inline code. The livedocs suggest it can but Forta, Camden, etc. don't have examples like that.

                I've posted a followup query here: http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=7&thr eadid=1335607&enterthread=y in case anyone has any ideas. It's related, but I thought it merited a new thread :)