Agents parameter and user ID

Help
2011-12-07
2013-04-25
  • Hi Eric, I read in the documentation that

    a) you can provide the ID of the user on whose behalf the agent is running. How do you do that?

    b) you can specify a parameter to the agent, can you please give an example how that would work? How do you specify the parameter, and how does the agent pick up the parameter?

    Thanks very much
    Eliott

     
  • I see - I can run it as signer, that's works out just fine.

    How about the way to pass the agent some parameters, and to pick up the parameters from inside the agent? How does that work?

    Thank you
    Eliott

     
  • I forgot to add… is the agent running simultaneously for multiple requests, or does it wait until each request is completed? Like parallel or serial mode?

    Thank you
    Eliott

     
  • Jean Jordaan
    Jean Jordaan
    2011-12-08

    Agents take positional arguments. I.e. you can call them like this:

    db=plominoDocument.getParentDatabase()
    db.MyAgent.runAgent('one', 2, 'three')
    

    and access the parameters as the "args" tuple in your formula.

     
  • Jean Jordaan
    Jean Jordaan
    2011-12-08

    Transactions in Zope are sequential and isolated from each other. Each web request (including any agents) is a transaction. Transactions either complete successfully or are rolled back.

    There may be more than one transaction in progress at once, but a new transaction will not see any changes from a previous transaction before the previous transaction has successfully completed.

    You can kick off an agent to run in a new transaction using the runAgent_async API call. However subsequent transactions will not see any changes from this agent before it completes successfully.

    If multiple transactions try to modify the same objects, you may see ConflictErrors. Zope tries to resolve these, but if you make every page view update the same counter, you will die from ConflictErrors. See http://www.zodb.org/documentation/articles/ZODB-overview.html#transactions for more detail.

     
  • That's most helpful, thank you!

    Eliott

     
  • However when I tried it, like below,

    db = plominoDocument.getParentDatabase()
    db.MyAgent.runAgent('1','2')

    it kept complaining that I provided 3 parameter and it only allows two!

    Can you tell me what I did wrong? :-)

    Thanks
    Eliott

     
  • Then, I changed it to a single parameter, and this is the error I received:

    File "Script (Python)", line 5, in action_AgentLauncher_plominoaction.2011-12-12.4577021776_script
    AttributeError: 'str' object has no attribute 'RESPONSE'
    Context is <PlominoForm> /Plone/knowledgebase/example-applications/agent-and-parameters/AgentLauncher
    4: db = plominoDocument.getParentDatabase()5: db.MyAgent.runAgent('1')

    Cheers,
    Eliott

     
  • Jean Jordaan
    Jean Jordaan
    2011-12-13

    My apologies, I was relying on my useless memory. In fact, these are your options:
    1) call the agent directly, passing parameters:

    logChange = db.getAgent('logChange')
    logChange(doc, docTitle, sectionTitle, author)
    

    And in the agent, access the parameters as members of 'args':

    doc, docTitle, sectionTitle, author = args
    

    Or
    2) call through the web and pass parameters as part of the request, e.g.:

    <a href="../myAgent/runAgent?category=Booklets">About booklets</a>
    
     
  • Hi again guys and happy new year!

    Would you have an actual example for this, where the agent receives parameters and returns a value? Because it does not work as you specified. I really need to get the agents working, because this would save time duplicating code. If the agent can receive a parameter and return a value, that would be the equivalent Plomino Nirvana :-)

    I get this error:

    File "Script (Python)", line 5, in action_Test_Button_script
    AttributeError: getAgent
    Context is <PlominoForm> /Members/minkosaurus/examples/try-it-here-first/Test

    4: db = context.getParentDatabase()
    5: myAgent = db.getAgent('AgentX')     # there is no such syntax in the documentation
    6: myAgent("Twang rules")

    when I change getAgent to getAgents (like in the documentation), I get this error:

    File "Script (Python)", line 5, in action_Test_Button_script
    TypeError: getAgents() takes exactly 1 argument (2 given)
    Context is <PlominoForm> /Members/minkosaurus/examples/try-it-here-first/Test

    4: db = context.getParentDatabase()
    5: myAgent = db.getAgents('AgentX')   #only one parameter, but it complains about two
    6: myAgent("Twang rules")

    Thanks mucho!
    Regards
    Eliott

     
  • Thank you very much, Eric, this helps a lot.

    Cheers
    Eliott

     
  • By the way that works in the cloud, I should specify. However my version is 1.12.1, and when I imported the agent application XML, and ran it, I got the same error, Attribute Error something something… I got this version by installing the default egg with buildout -N, but… how can I make sure I am running the latest code?

    Thanks
    Eliott

     
  • Eric Brehault
    Eric Brehault
    2012-01-09

    Hello,

    To make sure you use such or such version, you can pin the version in your buildout:
    in buildout.cfg, in the  section, you add:
    Plomino = 1.12.1

    Eric

     
  • OK, I see, and what is the latest version to use right now?