Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Nital Joshi
    Magic method Sleep on CPM script
    Topic posted January 7, 2019 by Nital JoshiRed Ribbon: 250+ Points, tagged Custom Process Models - CPMs 
    65 Views, 12 Comments
    Title:
    Magic method Sleep on CPM script
    Summary:
    sleep method is not working in CPM php script
    Content:

    Is there any way to halt execution of CPM (incident_update) for some time until All_Chat report not have the data?

    Sleep(40) not working for me. 

     

    Code Snippet:

    Comment

     

    • Vlad

      Is the CPM synchronous or asynchronous?

    • Nital Joshi

      Synchronous. Is it the issue ?

      • Vlad

        Yes. Synchronous CPMs have a maximum execution time of 5 seconds. I would suggest you use an asynchronous CPM where the max runtime is 157 seconds.

        • Nital Joshi

          Thanks Vlad for your quick response. I'll give a try and share the feedback with you.

          • Nital Joshi

            Hi Vlad,

            checkbox for sync/async is disabled. do I need to delete CPM and re create it ?

            • Vlad

              Yup

              • Nital Joshi

                I am receiving this error while deleting CPM

                • Vlad

                  Looks like the CPM is mapped with an event handler (e.g. Incident Create). You would have to remove these mappings before deleting the CPM. Simply de-associate the CPM from the events it's assigned to, save and deploy then try again.

                  • Nital Joshi

                    Hi Vlad,

                    Now working thanks! however its not solving my purpose :

                    There is one report All_Chats which save all chat data once terminated I need this inside Incident update CPM . I added sleep in CPM so once data in report CPM fetch logic will execute. Code is executing later and report have data however after awake object return null. If I re update incident it works. Any idea about this :

                    Code after sleep(120);

                    $cid = new RNCPHP\AnalyticsReportSearchFilter;
                    $cid->Name = 'incidentId';
                    $cid->Values = array($incident->ID); 
                    $filters_array = new RNCPHP\AnalyticsReportSearchFilterArray;
                    $filters_array[] = $cid;
                    $ar = RNCPHP\AnalyticsReport::fetch(149712);
                    $results = $ar->run(0, $filters_array);
                    $results = $ar->run(0, $filters_array);
                    $data = $results->next();
    • Vlad

      I would not recommend you use such a long sleep, it may cause issues such as a backed up SPM queue.

      I am not sure I understand what problem you are facing now. Does $obj suddenly return null? If so maybe you can save the $obj->ID into a variable when the CPM starts running and then fetch the incident again using this ID saved after the sleep. If this doesn't make sense please try to explain again what issue you are having. Don't assume we know anything about your implementation and be more careful with phrasing/punctuation :)

    • Nital Joshi

      Hi Vlad,

      To explain you in brief :

       There is default incident window open when agent accept chat in RN. There is one field Challenge which is mandatory as per our business requirement. Now This open window of incident is not saved in DB until and unless agent save it manually.(i.e. generated incident Id on window is dummy and  will be in DB after save only.)

      Now on termination of chat I want the incident Id associated with Chat Id. To achieve it I am using CPM : Incident_create which will fetch chat Id from report All_Chats.

      However what I observed is : CPM runs first and report All_Chat update later(based on logs my observation ). So I added sleep of 40 sec inside incident_crate(For Chat incident!). I see report have data for that incident however fetch logic after sleep not fetching data. If I update same incident it works. (It means code of fetch is correct!) . 

      Is there any alternative to achieve this ? Any why to add fetch or CPM on Chat table ?

       

    • Vlad

      Chat is not my area of expertise and I am still not sure I understand what your requirement is or what the problem is unfortunately. As far as I know, then incident is automatically associated with the chat it's created from...

      Perhaps you can check if the chat report runs on replication database, which may fall behind. Other than that I don't have any ideas.