Job Queue through NAV Webservice for mulitple Companies

ara3nara3n Member Posts: 9,256
edited 2014-06-04 in NAV Three Tier
I had posted on mibuso a while back on how to use two NAS instances to run job queue for unlimited amount of companies. Here is the link

viewtopic.php?f=7&t=22633. You had to purchase an additional NAS user license in order to use it. Dynamics NAV 2009 comes with web service, and you can publish any Code unit or Page by default. You will need to purchase one user but for webservice, but it much cheaper. In this blog, I will show you how to setup JOB QUEUE to schedule to run jobs across companies. The advantages of using Web Services is that you can run multiple jobs at the same time for multiple companies. What I’ve experienced with NAV 2009 Web Service is that once you call a web service function, you can disconnect and Service Tier will finish the job and commit the transaction.

In addition you don’t have to modify any processing/posting jobs that have dialog windows displayed. The Service tier simply ignores them. For example you can run adjust cost report without modifying any objects from Job queue. In addition, the solution I’ve created does not modify any existing objects!!!

You can download the fob and read more about it on my blog.
http://mibuso.com/blogs/ara3n/2009/01/2 ... companies/
Ahmed Rashed Amini
Independent Consultant/Developer


blog: https://dynamicsuser.net/nav/b/ara3n
«13

Comments

  • kinekine Member Posts: 12,562
    What to say... =D> =D> =D> 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • munib00munib00 Member Posts: 29
    Top quality.
  • garakgarak Member Posts: 3,263
    if i click on the link, the following message is displayed
    WordPress database error:
    INSERT INTO wp_38_ras_count (id) VALUES (NULL)

    WordPress database error:
    INSERT INTO wp_38_ras_image (id, createtime, word) VALUES (0, 1233215879, 'w6x27rn')

    WordPress database error:
    DELETE FROM wp_38_ras_count WHERE id = 0
    Do you make it right, it works too!
  • WaldoWaldo Member Posts: 3,412
    The idea is great! =D>

    But I have to think it through though... because when scheduling codeunits through web services ... what about the lack of optimistic concurrency?

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,256
    garak wrote:
    if i click on the link, the following message is displayed
    WordPress database error:
    INSERT INTO wp_38_ras_count (id) VALUES (NULL)

    WordPress database error:
    INSERT INTO wp_38_ras_image (id, createtime, word) VALUES (0, 1233215879, 'w6x27rn')

    WordPress database error:
    DELETE FROM wp_38_ras_count WHERE id = 0

    I've uploaded in here as well

    http://sites.google.com/site/ara3nfiles ... edirects=0
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Blog is working now. I fixed the missing tables.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • ara3nara3n Member Posts: 9,256
    I also submitted it to the download section on mibuso.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    Waldo wrote:
    The idea is great! =D>

    But I have to think it through though... because when scheduling codeunits through web services ... what about the lack of optimistic concurrency?


    could you clarify?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    Well, simple ... when two users are running the same webservice, and that web service is a codeunit in NAV ... there is no optimistic concurrency. You have to handle this manually.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • kinekine Member Posts: 12,562
    It will be handled in same way, as when you run these two codeunits in two different clients. There is nothing specific for WebServices in this... ot it is? :-k
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • WaldoWaldo Member Posts: 3,412
    yes there is.
    You won't get the message "the record has been changed since you last read it from the table...". No version control.

    Or at least, this has been told to me...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,256
    I just tested it and I do get the error.

    Another user has modified the record for this Item after you retrieved it from the database.  Enter your changes again in the updated window, or start the interrupted activity again.  Identification fields and values:  No.='1000'
    

    From webservice.

    My test codeunit looked like this.
    Item.GET('1000');
    SLEEP(10000);
    
    Item.VALIDATE(Description,'Bicycle WS');
    Item.MODIFY;
    


    So while the WS was waiting I modified the description on the item with another client.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    Sorry guys, I can't get into too much of detail .. it's just a warning I have been given a couple of times.
    I wish a Microsoft dude (freddy? :wink:) would stick his nose into this issue, because also I would like to know the details of it ... .

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,256
    So how do we get his attention? 8)
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    pm? :mrgreen:

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,256
    The way I I understood lack of optimistic concurrency was only when you published function that accepted a record. For example.
    You publish the customer Page, and then create a new Codeunit with function UpdateCustomerPostingGroup and it takes Customer as parameter. In Web Service Table you publish the codeunit with same Name as Customer. And in Visual Studio when you consume the Customer Page you'll see UpdateCustomerPostingGroup as a function to which you can pass the Current Record you are modifying. And that's where you'll see the issue.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    They 're not picking up this thread, are they?
    :(

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • DenSterDenSter Member Posts: 8,307
    I think they are reading it, but not answering. Maybe it's a touchy subject? :-k
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    No such thing as a touchy subject :?

    Anyway - it is correct that there is no optimistic concurrency and there are several ways to cope with this - not one single answer.

    I would love to discuss this, understand the issues you run into and discuss various solutions to these (which we then could post here). Any chance that some of you are going to Convergence in New Orleans? - maybe we could setup a discussion on this topic there?
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • ara3nara3n Member Posts: 9,256
    ara3n wrote:
    I just tested it and I do get the error.

    Another user has modified the record for this Item after you retrieved it from the database.  Enter your changes again in the updated window, or start the interrupted activity again.  Identification fields and values:  No.='1000'
    

    From webservice.

    My test codeunit looked like this.
    Item.GET('1000');
    SLEEP(10000);
    
    Item.VALIDATE(Description,'Bicycle WS');
    Item.MODIFY;
    


    So while the WS was waiting I modified the description on the item with another client.

    If there is no optimistic concurrency? I wouldn't get the above error, and I wouldn't be able to modify the item record. Web service had to lock the item record when it issued a get.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    Ok - you are right, my bad....

    We are using optimistic concurrency with no conflict resolution - so if two users modify different fields in the same record, the last user to update gets the error. Web Services here is just like a user.

    You can provoke this with 2 clients as well - open 2 clients (Classic or RTC) - open item 1000 in both - modify something in one client and close the card. Modify something in the other client and close the card and you get the error - I guess it has been like that forever.

    So the webservice codeunit is the same - the

    ITEM.GET

    is reading the record and if anything changes the record from that time and until it tries to write the record back - it will fail.

    Re-reading the thread - I guess the question is whether or not this applies to codeunits that are published as extention functions to pages - right?
    I am pretty sure that it does - meaning that you cannot do like this:
    Item_Service service = new Item_Service();
    service.UseDefaultCredentials = true;
    Item item = service.Read("1000");
    service.Test(item.Key);   // <-- This is the function updating the Description
    item.Shelf_No = "FF";
    service.Update(ref item); // <-- This will fail
    
    You would have to re-read the Item after calling the Test function, since the extension function gets the key and re-reads a representation of the record itself.
    That is at least what I know/have tried - let me know whether there are anything I should try to investigate?
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • ara3nara3n Member Posts: 9,256
    That's good news, and thank you for the confirmation.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • WaldoWaldo Member Posts: 3,412
    yes indeed, this is good news [-o< .

    I'm going to be at Convergence ... and i would love to go into this furthermore :)

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • elwin68elwin68 Member Posts: 153
    I have used the installation of the NAS and webservice on our own server last week. Everything worked fine until today.
    Nothing is changed at the codeunit RunJob. The only change at the server is a windows update for Internet Explorer 8.

    Today the Job Queue Log Entries give me the following error: Http Error 500: Internal Server Error

    The event viewer of the server gives me the following error:
    Type: Microsoft.Dynamics.Nav.Service.WebServices.ServiceBrokerException
    Message: Method "RunJob" is invalid!

    Does anyone can give me a clue?

    Thanks in advance.
  • ara3nara3n Member Posts: 9,256
    check and make sure the you can access the web service through IE and that the runJob is published.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • elwin68elwin68 Member Posts: 153
    I have already done that.
    The webservice is running and accessible and RunJob is published.
  • ara3nara3n Member Posts: 9,256
    I am guessing you've already restarted the service tier?
    Next idea would be to reinstall the server tier.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    I am not sure that I understand what the questions are?
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • ara3nara3n Member Posts: 9,256
    hello Freddy. I was asking about the following thread.

    viewtopic.php?f=32&t=34672
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • elwin68elwin68 Member Posts: 153
    I have restarted the service tier and restarted the computer.
    After this I have made a virtual PC with NAV2009 and added the codeunits and the NAS.
    The same error occures: Http Error 500: Internal Server Error

    The event viewer gives the same error too: Message: Method "RunJob" is invalid!

    When have have more time I will try it again. Thanks for your time for now.
Sign In or Register to comment.