How to handled timed out?

Jul 20, 2010 at 10:19 PM
So PerceptiveMCAPI uses apiException to swallow exceptions from the underlying RPC layer and add them to the list of error messages that are returned. Have you thought about not swallowing the exceptions and letting the caller deal with them? I'd like to handle timed out exceptions from the RPC layer when I call listBatchSubscribe.Execute() properly. I suppose I can by parsing out the listBatchSubscribeOutput error values to determine if I've got the right exception but it seems like a poor approach. Perhaps the cleanest would be for PerceptiveMCAPI to rebundle the exceptions that are relevant to the caller and swallow others as error messages? Thoughts? Thanks, Cymen
Jul 20, 2010 at 10:31 PM
Edited Jul 20, 2010 at 10:31 PM
An example of how I might currently check for the "timed out" exception: http://pastebin.com/3PM4P6Su
Coordinator
Jul 21, 2010 at 12:20 AM

I combined the other post here as well.... I'm poking around trying to figure out how to set api_Timeout to increase it on failure. Any pointers? Thanks, Cymen

The api_Timeout is set as a configuration parameter and is not changable on an individual method call -- that may be something I'll look into in the future.  Otherwise you can modify the default of 90,000 ms in the web.config settings. 

Remember, the api_Timeout only controls the xml-rpc request timeout -- it doesn't apply to other timeout values; server, page scripts, network, etc.  From your example of checking for an "ex" that tells me that the error is NOT an xml-rpc error as the CookComputing xmlrpc errors provide a numeric FaultCode value.

As far as 'increase it on failure' -- I'm not sure what you are trying to accomplish in that scenario, and whether even allowing that value to be changed on an individual method call would do what you're trying to accomplish.

At any rate, regardless of method called and error received, when an error occurs in an Api method call to MailChimp, there isn't any ability to 'recover' and continue -- it's failed. So I'm not sure how you would want to 'deal with them' differently than what you can already do by examining the exception messages.  In any event, the source is available for you to modify it as you wish, including re-throwing errors if you wish to deal with them yourself.

David

Jul 21, 2010 at 6:14 AM
Edited Jul 21, 2010 at 6:39 AM

This is what I'm seeing:

Sync::PushContactsToProvider begin MailChimp listBatchSubscribe request with 5000 contacts
ex: The operation has timed out

   at System.Net.HttpWebRequest.GetResponse()
   at CookComputing.XmlRpc.XmlRpcClientProtocol.GetWebResponse(WebRequest request)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(Object clientObj, MethodInfo mi, Object[] parameters)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(MethodInfo mi, Object[] Parameters)
   at XmlRpcProxy237e7148-9726-4efd-b451-c2c2f2891016.listBatchSubscribe(Stringapikey, String id, XmlRpcStruct batch, Boolean double_optin, Boolean update_existing, Boolean replace_interests)
   at PerceptiveMCAPI.Methods.listBatchSubscribe.ExecuteXmlRpc()

To clarify, I'm using PerceptiveMCAPI in a service not a web project. Should this have resulted in a numeric error? I'll take a closer look at the source. The above is from a log and I'm logging all the errors in the listBatchSubscribeOutput.

Cymen

Coordinator
Jul 21, 2010 at 4:55 PM
Edited Jul 21, 2010 at 4:56 PM
In the case of xmlrpc api calls, there are 2 catch blocks, there first tests for an XmlRpcFaultException, the second for a generic exception.
So in the case of it being an exception of the xmlrpc request itself, yes, you should get a numeric exception code that CookComputing library returns.

I've only used web services a handful of times in very simple scenarios -- so I'm no expert on them by any stretch of the imagination.
Other than that, you're ahead of me -- I've been trying to get the bandwidth to test out the wrapper as part of a webservice for some time.
I was actually planning on using the wrapper in a service as a way to learn more about web services and as part of a product offering -- sadly I haven't had the time to do that yet.

I suspect that it's either an execution timeout which can be adjusted via the <httpRuntime executionTimeout = "number"> web.config setting
(see... http://msdn.microsoft.com/en-us/library/e1f13641.aspx)
or
maybe your proxy class Timeout property needs to be increased. I found an example...

WebReference.ProxyClass myProxy = new WebReference.ProxyClass();
// Set the timeout in milliseconds -- e.g. 100 seconds
myProxy.Timeout = 100000;

... hopefully one of those might help.

Let me know,

David
Aug 13, 2010 at 10:07 PM

To be honest, I'm not following at all. I'm using PerceptiveMCAPI directly to make the calls. I'm not doing any sort of HTTP GET or POST outside or proxying anything myself. I do have an app.config but not a web.config as it isn't a web project. But I'm still getting timeouts like this one:

 

Sync::PushContactsToProvider begin push of 2500 contacts (batch mode)
ex: The operation has timed out

   at System.Net.HttpWebRequest.GetResponse()
   at CookComputing.XmlRpc.XmlRpcClientProtocol.GetWebResponse(WebRequest request)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(Object clientObj, MethodInfo mi, Object[] parameters)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(MethodInfo mi, Object[] Parameters)
   at XmlRpcProxy710a53bf-4a2f-4eb7-80e9-7b2ed3641963.listBatchSubscribe(String apikey, String id, XmlRpcStruct batch, B
oolean double_optin, Boolean update_existing, Boolean replace_interests)
   at PerceptiveMCAPI.Methods.listBatchSubscribe.ExecuteXmlRpc()

Sync::PushContactsToProvider MailChimp listBatchSubscribe request timed out -- sleeping for 1 minutes then trying again.

Sync::PushContactsToProvider begin push of 2500 contacts (batch mode)
ex: The operation has timed out

   at System.Net.HttpWebRequest.GetResponse()
   at CookComputing.XmlRpc.XmlRpcClientProtocol.GetWebResponse(WebRequest request)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(Object clientObj, MethodInfo mi, Object[] parameters)
   at CookComputing.XmlRpc.XmlRpcClientProtocol.Invoke(MethodInfo mi, Object[] Parameters)
   at XmlRpcProxy710a53bf-4a2f-4eb7-80e9-7b2ed3641963.listBatchSubscribe(String apikey, String id, XmlRpcStruct batch, B
oolean double_optin, Boolean update_existing, Boolean replace_interests)
   at PerceptiveMCAPI.Methods.listBatchSubscribe.ExecuteXmlRpc()

Sync::PushContactsToProvider MailChimp listBatchSubscribe request timed out -- sleeping for 2 minutes then trying again.

Sync::PushContactsToProvider begin push of 2500 contacts (batch mode)
Aug 13, 2010 at 10:13 PM

Ah! I see what you're hinting about. I think I need to grab the source for PerceptiveMCAPI and start hacking on it though to do these things. I'll try it.

Aug 13, 2010 at 10:31 PM

I went down to 1,000 contacts per listBatchSubscribe and I'm not getting the timeout. I'll probably just live with that.

Aug 24, 2010 at 8:53 PM

I'm continuing to have problems with this even after dropping down batch size to 500 members. So I dug into it today. I made two changes:

 

Application\MCAPISettings.cs: added set {} to api_Timeout

 

      public static int api_Timeout
      {
         get
         {
            int it; int.TryParse( Instance.MCAPI.Timeout, out it );
            if ( it == 0 ) return 90000;  // default
            return it;
         }
         set
         {
            Instance.MCAPI.Timeout = value.ToString();
         }
      }

 

Application\MCAPIconfig.cs: added set {} to Timeout

 

      [ConfigurationProperty( "Timeout", DefaultValue = "90000" )]
      internal string Timeout
      {
         get { return this["Timeout"] as string; }
         set {
             int timeout;
             if (int.TryParse(value, out timeout))
             {
                 if (timeout >= 90000)
                     this["Timeout"] = timeout.ToString();
             }
         }
      }
Aug 24, 2010 at 8:54 PM

Then to actually change the timeout I made the following call in my code before beginning API calls:

 

            MCAPISettings.api_Timeout = 300000;             // 1.5 minutes default, now set to 5 minutes
Aug 24, 2010 at 9:05 PM
Edited Aug 24, 2010 at 9:39 PM

So that didn't actually help. Now to go down to the XML-RPC.net layer and see if we can somehow pass this timeout value down into that code. It needs to go all the way down to the GetResponse() call.

Aug 24, 2010 at 9:25 PM

It appears that timeout value is indeed passed down into the XML-RPC.net. I misread my log -- indeed the push of 5,000 contacts took longer than 5 minutes or 300,000 milleseconds. I've now adjusted to 1,000 contacts with the same 5 minute timeout and the API call is taking just under 3 minutes to complete (servers @MailChimp are sluggish today).

Aug 24, 2010 at 9:26 PM

So can we add the ability to change the timeout to the standard release? I'd prefer not to patch each release to do this although it certainly isn't onerous to do so.

Thanks!

Cymen

Coordinator
Aug 25, 2010 at 6:10 PM
Edited Aug 25, 2010 at 6:12 PM

You already can -- sort of.

You can change the MCAPISettings.api_Timeout value on a system-wide basis using an override value in the web.config file
-- you just can't do it on an individual method call basis.

I will put it on the list for the next release, but I suspect I'll do it differently; I also will likely change the SecureAccess as well.

My initial thought is I'll most likely change those entries from "Api Control" types to be "Wrapper Directives"
-- in other words, carried in the BaseInput class and changeable after the Input class is instantiated, similar to AccessType, etc.

Aug 25, 2010 at 6:57 PM

My problem is trying to figure out how to get those settings that can be put into web.config into app.config (for regular C# service/program). I haven't quite figured out if it is possible or if it would require changes to the code to work with either configuration file.

I'm happy with whatever method you come up with. I can look some more at the differences in reading from and putting entries in app.config versus web.config.

Coordinator
Aug 25, 2010 at 8:17 PM
Edited Aug 25, 2010 at 8:38 PM

Ah sorry, I forgot about that when I answered.

Really there is little or no difference between web.config & app.config -- they both share the same format & both are processed by classes in the System.configuration namespace.

I just tried a windows form app and it worked OK.... here's what I did.

1) First make sure you have a reference to System.configuration in your References, if not add it.

2) In addition to the  PerceptiveMCAPI  'using' statements mentioned in the documentation, add ... using System.Configuration;   Ignore this - it's not necessary

3) in your app.config use the format as in the documentation, my example is something like....

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <configSections>
      <section name="MailChimpAPIconfig" type="PerceptiveMCAPI.MCAPISettings, PerceptiveMCAPI"/>
   </configSections>

   <MailChimpAPIconfig>
      <MCAPI
         SecureAccess="False"
         AccessType="Serial"
         OutputType="JSON"
         MethodType="POST"
         Validate="False"
	 Timeout="300000"
         campaign_authenticate="True"
         apikey="my-apikey"
         listUnsubscribe_delete_member="True"
         listUnsubscribe_send_goodbye="False"
         listSubscribe_double_optin="False"
        />
   </MailChimpAPIconfig>

</configuration>

 

Hope that helps.

 

David

 

   
      
   

   
      
   

 

Aug 26, 2010 at 10:07 PM
Edited Aug 26, 2010 at 10:48 PM

Sorry, long day. It is working -- I missed this part:

   <configSections>
      <section name="MailChimpAPIconfig" type="PerceptiveMCAPI.MCAPISettings, PerceptiveMCAPI"/>
   </configSections>
Not sure how! Thanks!