Announcement

Collapse
No announcement yet.

MvASYNCHRONOUS -- Does anyone have an example

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MvASYNCHRONOUS -- Does anyone have an example

    If you have an example or recommendations on its usage, please share. I assume the Scheduled Task feature in Miva uses it in ScheduledTasks_Spawn_AsynchronousTask() in the LSK but alas this function is not included.

    A scheduled task module is not that difficult to write, but that would be overkill for my situation.
    Ray Yates
    "If I have seen further, it is by standing on the shoulders of giants."
    --- Sir Isaac Newton

    #2
    Code:
    <MVASYNC>
        <MvIF EXPR = "{ NOT [ g.Module_Library_Utilities ].Initialize_Async_Environment( 'scheduled', 'STORE_CODE_HERE' ) }">
            <MvFUNCTIONRETURN>
        </MvIF>
    
        ...
    </MvASYNC>
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      David, Thanks for the snippet. What is the use case? Or, what issue would this potentially solve or help?

      Scott
      Need to offer Shipping Insurance?
      Interactive Design Solutions https://www.myids.net
      MivaMerchant Business Partner | Certified MivaMerchant Web Developer
      Competitive Rates, Custom Modules and Integrations, Store Integration
      AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
      My T-shirt Collection is mostly MivaCon T-shirts!!

      Comment


        #4
        Originally posted by RayYates View Post
        A scheduled task module is not that difficult to write, but that would be overkill for my situation.
        Having it in that location can have other benefit though. We or a store operator may have reason to want to temporarily disable scheduled tasks, and turning them off is quite easy in the Scheduled Tasks location, vs a module firing its own and possibly creating an unexpected event. Scheduled Tasks also have useful logging.
        David Hubbard
        CIO
        Miva
        [email protected]
        http://www.miva.com

        Comment


          #5
          I use mvasync for anything that might time out since the async process is, from what I've been told, a roughly 60 minute process done in the background. If I need to show progress I create a flat file that has whatever progress data I want and check for it if the user triggers a progress display. Important to know that mvasync won't work with store functions or anything like that unless you initialize the store environment, similar to how you'd need to init the store environment for mvprocessupload.
          M.A.D.* since 1997

          http://www.scotsscripts.com

          *miva application developers

          Comment


            #6
            Here is one of our examples. We have started to use this wherever possible LOVE IT!
            This code adds an email to our mailing list company upon a new sign up to our service (orangemailer.co)

            <MvASYNCHRONOUS>
            <MvASSIGN NAME="l.crlf" VALUE="{ asciichar(13) $ asciichar(10) }">
            <MvAssign name="grant_type" value="client_credentials">
            ...
            <MvCAPTURE VARIABLE = "l.json">
            <MvEval expr="{ '{
            "emails":[
            {
            "email":"' $ email $ '",
            "variables":{
            "First_Name":"' $ firstname $ '",
            "Last_Name":"' $ lastname $ '",
            "name": "' $ fullname $ '"
            }
            }]
            }' }">
            </MvCapture>
            <MvCall action="{ 'https://api.sendpulse.com/addressbooks/71832/emails' }" method="RAW" HEADERS="{ 'Authorization: Bearer ' $ l.theToken $ l.crlf }" CONTENT-TYPE="application/json" FIELDS="l.json" FLAGS="noparse">
            </MvCall>
            </MvASYNCHRONOUS>
            William Gilligan - Orange Marmalade, Inc.
            www.OrangeMarmaladeinc.com

            Comment


              #7
              Hey Bill,

              What issue does it solve or make easier?

              Scott
              Need to offer Shipping Insurance?
              Interactive Design Solutions https://www.myids.net
              MivaMerchant Business Partner | Certified MivaMerchant Web Developer
              Competitive Rates, Custom Modules and Integrations, Store Integration
              AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
              My T-shirt Collection is mostly MivaCon T-shirts!!

              Comment


                #8
                Hey Scott,
                In this case - we pass the new user directly to our outsourced mailing list - with no waiting on the mvcall response.
                We don't care if there is an error - cause nothing is dependent on the email getting entered.
                And since we don't have to wait for the callvalue - we just keep going. Saves some amount of time.
                William Gilligan - Orange Marmalade, Inc.
                www.OrangeMarmaladeinc.com

                Comment


                  #9
                  Reviving this thread...hopefully...

                  Line 1128: MvASYNCHRONOUS: Maximum number of asynchronous tasks exceeded
                  I have no idea how the max number was reached. How can I fix this? What are the conditions for using MvASYNCHRONOUS?

                  Notes: In a UTILS module, I am wrapping the MvCall with MvASYNCHRONOUS similar to the example by Bill G earlier in this thread trying to prevent a timeout.
                  I see no where in this store that this kind of Async process would be running. I am also not seeing much documentation. Seems like it's straight forward, but, not working.

                  Scott
                  Need to offer Shipping Insurance?
                  Interactive Design Solutions https://www.myids.net
                  MivaMerchant Business Partner | Certified MivaMerchant Web Developer
                  Competitive Rates, Custom Modules and Integrations, Store Integration
                  AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
                  My T-shirt Collection is mostly MivaCon T-shirts!!

                  Comment


                    #10
                    From the web site: http://www.mivascript.com/item/MvASYNCHRONOUS.html
                    "The number of asynchronous tasks allowed, the timeout time for an asynchronous task, and an absolute timeout for miva_async_sleep are all configurable."

                    I assume (although I have not run into this issue) that Empressa has a configuration for it. Unfortunately I can no longer locate the Empressa configuration docs.

                    Sounds to me like you may be starting to many asynchronous tasks (maybe a loop or something?
                    William Gilligan - Orange Marmalade, Inc.
                    www.OrangeMarmaladeinc.com

                    Comment


                      #11
                      Unfortunately, I currently don't have access (FTP). And I wouldn't be able to restart Empressa if I needed to change the config.
                      I looked at the compiler readme and I don't recall that it explains how many tasks in the miva_async_sleep function. And I am not sure where that function would be placed.

                      In this case there are no loops. Just one MvCall to run one endpoint function hoping to run some code to process the response. The endpoint can take time if there is lots of data to gather for the response.

                      Scott
                      Need to offer Shipping Insurance?
                      Interactive Design Solutions https://www.myids.net
                      MivaMerchant Business Partner | Certified MivaMerchant Web Developer
                      Competitive Rates, Custom Modules and Integrations, Store Integration
                      AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
                      My T-shirt Collection is mostly MivaCon T-shirts!!

                      Comment


                        #12
                        Hi Scott,
                        Do you know what version Empressa is running?
                        William Gilligan - Orange Marmalade, Inc.
                        www.OrangeMarmaladeinc.com

                        Comment


                          #13
                          It's the latest version.
                          Need to offer Shipping Insurance?
                          Interactive Design Solutions https://www.myids.net
                          MivaMerchant Business Partner | Certified MivaMerchant Web Developer
                          Competitive Rates, Custom Modules and Integrations, Store Integration
                          AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
                          My T-shirt Collection is mostly MivaCon T-shirts!!

                          Comment


                            #14
                            It sounds like the site has their maxasynctasks directive set to a relatively low value in their mivavm.conf. There could also be scheduled tasks already running. Using MvASYNC probably isn't the best bet in this case anyway. If your MvCALL failed within it you would have no idea. You should look at alternate solutions such as having the MvCALL outside of the MvASYNC and just waiting for it complete. If it's slow maybe find a way to speed up the response from the server? You could also trigger a scheduled task to run and move your MvCALL into the API functions for scheduled tasks. That would probably better handle all the spawning for you.
                            David Carver
                            Miva, Inc. | Software Developer

                            Comment


                              #15
                              Thanks, David. I think I am now confused from this whole thread. I am also not understanding why MvCall would be run outside of Async.
                              I have a single endpoint that, based on passed parameters, can take just shy of 120 seconds. Was I wrong to conclude that the Async method could allow the MvCall to return the JSON response?

                              Here's what I am doing. l.myurl is a confirmed URL I can test with Postman and I get a confirmed JSON response; usually in about 110 seconds. So, I know the URL is solid.
                              The prodquery_json is simply the query parameters.
                              I am doing this in a UTILS Admin screen/tab right now, but it will be a scheduled task if it matters.

                              Code:
                              <MvASYNCHRONOUS>
                                  <MvAssign name="grant_type" value="client_credentials">
                                  <MvCALL METHOD            = "POST"
                                                      TIMEOUT         = "85"
                                              ACTION          = "{ l.myurl }"
                                              CONTENT-TYPE    = "application/json"
                                              HEADERS         = "{ 'Authorization: Bearer ' $ l.tokenID $ asciichar( 13 ) $ asciichar( 10 ) }"
                                              FIELDS          = "l.prodquery_json">               
                                              <MvASSIGN NAME = "l.returnJSON" VALUE = "{ s.callvalue }">
                                  </MvCALL>
                              </MvASYNCHRONOUS>
                              Notes: the timeout is the last number I've attempted, with/without Async. I don't know about the grant type so that's another question. But Bill has it in his example and though it was worth keeping.
                              And there is a question of using the miva_async_sleep function. Where/How does this function get applied?

                              Thanks,

                              Scott
                              Need to offer Shipping Insurance?
                              Interactive Design Solutions https://www.myids.net
                              MivaMerchant Business Partner | Certified MivaMerchant Web Developer
                              Competitive Rates, Custom Modules and Integrations, Store Integration
                              AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
                              My T-shirt Collection is mostly MivaCon T-shirts!!

                              Comment

                              Working...
                              X