<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14664] CalendarServer/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14664">14664</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-04-08 06:50:32 -0700 (Wed, 08 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Schedule work items fail temporarily if remote servers are down.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavstdconfigpy">CalendarServer/trunk/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingischeduledeliverypy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingworkpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingischeduletesttest_cross_pod_schedulingpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_cross_pod_scheduling.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py (14663 => 14664)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/stdconfig.py        2015-04-06 21:13:15 UTC (rev 14663)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py        2015-04-08 13:50:32 UTC (rev 14664)
</span><span class="lines">@@ -761,6 +761,8 @@
</span><span class="cx">                 &quot;AutoReplyDelaySeconds&quot;               : 5,          # Time delay for sending an auto reply iTIP message
</span><span class="cx">                 &quot;AttendeeRefreshBatchDelaySeconds&quot;    : 5,          # Time after an iTIP REPLY for first batched attendee refresh
</span><span class="cx">                 &quot;AttendeeRefreshBatchIntervalSeconds&quot; : 5,          # Time between attendee batch refreshes
</span><ins>+                &quot;TemporaryFailureDelay&quot;               : 60,         # Delay in seconds before a work item is executed again after a temp failure
+                &quot;MaxTemporaryFailures&quot;                : 10,         # Max number of temp failure retries before treating as a permanent failure
</ins><span class="cx">             },
</span><span class="cx"> 
</span><span class="cx">             &quot;Splitting&quot;: {
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingischeduledeliverypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py (14663 => 14664)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py        2015-04-06 21:13:15 UTC (rev 14663)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/delivery.py        2015-04-08 13:50:32 UTC (rev 14664)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx"> 
</span><span class="cx"> from calendarserver.version import version
</span><span class="cx"> 
</span><del>-from twext.internet.gaiendpoint import GAIEndpoint
</del><ins>+from twext.internet.gaiendpoint import GAIEndpoint, MultiFailure
</ins><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from txweb2 import responsecode
</span><span class="cx"> from txweb2.client.http import ClientRequest
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx"> from txweb2.stream import MemoryStream
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, DeferredList, returnValue
</span><del>-from twisted.internet.error import ConnectionDone
</del><ins>+from twisted.internet.error import ConnectionDone, ConnectionRefusedError
</ins><span class="cx"> from twisted.internet.protocol import Factory
</span><span class="cx"> from twisted.python.failure import Failure
</span><span class="cx"> 
</span><span class="lines">@@ -264,6 +264,15 @@
</span><span class="cx">                 raise ValueError(&quot;Incorrect server response status code: {code}&quot;.format(code=response.code))
</span><span class="cx"> 
</span><span class="cx">         except Exception, e:
</span><ins>+            # Check for connection failure
+            if isinstance(e, MultiFailure) and not self.scheduler.isfreebusy:
+                all_connections_failed = all([isinstance(err.value, ConnectionRefusedError) for err in e.failures])
+            else:
+                all_connections_failed = False
+
+            # We will return MESSAGE_PENDING if we failed to connect to the remote server, otherwise SERVICE_UNAVAILABLE
+            failed_status = iTIPRequestStatus.MESSAGE_PENDING if all_connections_failed else iTIPRequestStatus.SERVICE_UNAVAILABLE
+
</ins><span class="cx">             # Generated failed responses for each recipient
</span><span class="cx">             log.error(
</span><span class="cx">                 &quot;Could not do server-to-server request : {req} {exc}&quot;,
</span><span class="lines">@@ -276,7 +285,7 @@
</span><span class="cx">                     (ischedule_namespace, &quot;recipient-failed&quot;),
</span><span class="cx">                     &quot;Server-to-server request failed&quot;,
</span><span class="cx">                 ))
</span><del>-                self.responses.add(recipient.cuaddr, Failure(exc_value=err), reqstatus=iTIPRequestStatus.SERVICE_UNAVAILABLE)
</del><ins>+                self.responses.add(recipient.cuaddr, Failure(exc_value=err), reqstatus=failed_status)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingischeduletesttest_cross_pod_schedulingpy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_cross_pod_scheduling.py (0 => 14664)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_cross_pod_scheduling.py                                (rev 0)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_cross_pod_scheduling.py        2015-04-08 13:50:32 UTC (rev 14664)
</span><span class="lines">@@ -0,0 +1,281 @@
</span><ins>+##
+# Copyright (c) 2012-2015 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from pycalendar.datetime import DateTime
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twistedcaldav.ical import Component
+from txdav.caldav.datastore.scheduling.ischedule.delivery import IScheduleRequest
+from txdav.caldav.datastore.scheduling.ischedule.resource import IScheduleInboxResource
+from txdav.common.datastore.podding.test.util import MultiStoreConduitTest
+from txweb2.dav.test.util import SimpleRequest
+from twext.internet.gaiendpoint import MultiFailure
+from twisted.python.failure import Failure
+from twisted.internet.error import ConnectionRefusedError
+from twext.enterprise.jobqueue import JobItem
+
+class TestCrossPodScheduling (MultiStoreConduitTest):
+
+
+    now = {
+        &quot;now&quot;: DateTime.getToday().getYear(),
+        &quot;now1&quot;: DateTime.getToday().getYear() + 1,
+    }
+
+    @inlineCallbacks
+    def setUp(self):
+        &quot;&quot;&quot;
+        Setup fake hook-up between pods
+        &quot;&quot;&quot;
+        @inlineCallbacks
+        def _fakeSubmitRequest(iself, ssl, host, port, request):
+
+            if self.refuseConnection:
+                raise MultiFailure((Failure(ConnectionRefusedError()),))
+            else:
+                pod = (port - 8008) / 100
+                inbox = IScheduleInboxResource(self.site.resource, self.theStoreUnderTest(pod), podding=True)
+                response = yield inbox.http_POST(SimpleRequest(
+                    self.site,
+                    &quot;POST&quot;,
+                    &quot;http://{host}:{port}/podding&quot;.format(host=host, port=port),
+                    request.headers,
+                    request.stream.mem,
+                ))
+                returnValue(response)
+
+        self.refuseConnection = False
+        self.patch(IScheduleRequest, &quot;_submitRequest&quot;, _fakeSubmitRequest)
+        yield super(TestCrossPodScheduling, self).setUp()
+
+
+    def configure(self):
+        super(TestCrossPodScheduling, self).configure()
+
+        # Enable the queue and make it slow
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;Enabled&quot;, True)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;RequestDelaySeconds&quot;, 0.1)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;ReplyDelaySeconds&quot;, 0.1)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;AttendeeRefreshBatchDelaySeconds&quot;, 0.1)
+        self.patch(self.config.Scheduling.Options.WorkQueues, &quot;TemporaryFailureDelay&quot;, 5)
+
+
+    @inlineCallbacks
+    def test_simpleInvite(self):
+        data_organizer = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid_data
+DTSTART:{now1:04d}0102T160000Z
+DURATION:PT1H
+CREATED:20060102T190000Z
+DTSTAMP:20051222T210507Z
+SUMMARY:data01_2
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE:mailto:puser02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;).format(**self.now)
+
+        # Organizer schedules
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name=&quot;user01&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        yield calendar.createCalendarObjectWithName(&quot;1.ics&quot;, Component.fromString(data_organizer))
+        yield self.commitTransaction(0)
+
+        yield self.waitAllEmpty()
+
+        # Data for user02
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name=&quot;user02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        self.assertEqual(cobjs[0].uid(), &quot;uid_data&quot;)
+        yield self.commitTransaction(0)
+
+        # Data for puser02
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(1), name=&quot;puser02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        self.assertEqual(cobjs[0].uid(), &quot;uid_data&quot;)
+        yield self.commitTransaction(1)
+
+
+    @inlineCallbacks
+    def test_connectionRefusedForOrganizer(self):
+        data_organizer = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid_data
+DTSTART:{now1:04d}0102T160000Z
+DURATION:PT1H
+CREATED:20060102T190000Z
+DTSTAMP:20051222T210507Z
+SUMMARY:data01_2
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE:mailto:puser02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;).format(**self.now)
+
+        # Stop cross-pod connection from working
+        self.refuseConnection = True
+
+        # Organizer schedules
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name=&quot;user01&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        yield calendar.createCalendarObjectWithName(&quot;1.ics&quot;, Component.fromString(data_organizer))
+        yield self.commitTransaction(0)
+
+        while True:
+            jobs = yield JobItem.all(self.theTransactionUnderTest(0))
+            yield self.commitTransaction(0)
+            if len(jobs) == 1 and jobs[0].failed &gt; 0:
+                break
+
+        # Data for user02
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name=&quot;user02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        self.assertEqual(cobjs[0].uid(), &quot;uid_data&quot;)
+        yield self.commitTransaction(0)
+
+        # Data for puser02
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(1), name=&quot;puser02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        self.assertEqual(len(cobjs), 0)
+        yield self.commitTransaction(1)
+
+        # Now allow cross-pod to work
+        self.refuseConnection = False
+
+        yield self.waitAllEmpty()
+
+        # Data for puser02
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(1), name=&quot;puser02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        self.assertEqual(cobjs[0].uid(), &quot;uid_data&quot;)
+        yield self.commitTransaction(1)
+
+
+    @inlineCallbacks
+    def test_connectionRefusedForAttendee(self):
+        data_organizer = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid_data
+DTSTART:{now1:04d}0102T160000Z
+DURATION:PT1H
+CREATED:20060102T190000Z
+DTSTAMP:20051222T210507Z
+SUMMARY:data01_2
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE:mailto:puser02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;).format(**self.now)
+
+        data_attendee = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:uid_data
+DTSTART:{now1:04d}0102T160000Z
+DURATION:PT1H
+CREATED:20060102T190000Z
+DTSTAMP:20051222T210507Z
+SUMMARY:data01_2
+ORGANIZER:mailto:user01@example.com
+ATTENDEE:mailto:user01@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE;PARTSTAT=DECLINED:mailto:puser02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;).format(**self.now)
+
+        # Organizer schedules
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name=&quot;user01&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        yield calendar.createCalendarObjectWithName(&quot;1.ics&quot;, Component.fromString(data_organizer))
+        yield self.commitTransaction(0)
+
+        yield self.waitAllEmpty()
+
+        # Data for user02
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(0), name=&quot;user02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        self.assertEqual(cobjs[0].uid(), &quot;uid_data&quot;)
+        yield self.commitTransaction(0)
+
+        # Data for puser02
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(1), name=&quot;puser02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        self.assertEqual(cobjs[0].uid(), &quot;uid_data&quot;)
+        yield self.commitTransaction(1)
+
+        # Stop cross-pod connection from working
+        self.refuseConnection = True
+
+        # Attendee changes
+        home = yield self.homeUnderTest(txn=self.theTransactionUnderTest(1), name=&quot;puser02&quot;, create=True)
+        calendar = yield home.childWithName(&quot;calendar&quot;)
+        cobjs = yield calendar.calendarObjects()
+        yield cobjs[0].setComponent(Component.fromString(data_attendee))
+        yield self.commitTransaction(1)
+
+        while True:
+            jobs = yield JobItem.all(self.theTransactionUnderTest(1))
+            yield self.commitTransaction(1)
+            if len(jobs) == 1 and jobs[0].failed &gt; 0:
+                break
+
+        # Organizer data unchanged
+        cobj = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield cobj.componentForUser()
+        self.assertTrue(&quot;DECLINED&quot; not in str(comp))
+        yield self.commitTransaction(0)
+
+        # Now allow cross-pod to work
+        self.refuseConnection = False
+
+        yield self.waitAllEmpty()
+
+        # Organizer data changed
+        cobj = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;, name=&quot;1.ics&quot;)
+        comp = yield cobj.componentForUser()
+        self.assertTrue(&quot;DECLINED&quot; in str(comp))
+        yield self.commitTransaction(0)
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingworkpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py (14663 => 14664)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py        2015-04-06 21:13:15 UTC (rev 14663)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/work.py        2015-04-08 13:50:32 UTC (rev 14664)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx"> from twext.enterprise.dal.syntax import Select, Insert, Delete, Parameter
</span><span class="cx"> from twext.enterprise.locking import NamedLock
</span><span class="cx"> from twext.enterprise.jobqueue import WorkItem, WORK_PRIORITY_MEDIUM, JobItem, \
</span><del>-    WORK_WEIGHT_5
</del><ins>+    WORK_WEIGHT_5, JobTemporaryError
</ins><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, Deferred
</span><span class="lines">@@ -279,7 +279,26 @@
</span><span class="cx">         return changed
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def checkTemporaryFailure(self, results):
+        &quot;&quot;&quot;
+        Check to see whether whether a temporary failure should be raised as opposed to continuing on with a permanent failure.
</ins><span class="cx"> 
</span><ins>+        @param results: set of results gathered in L{extractSchedulingResponse}
+        @type results: L{list}
+        &quot;&quot;&quot;
+        if all([result[1] == iTIPRequestStatus.MESSAGE_PENDING_CODE for result in results]):
+            job = yield JobItem.load(self.transaction, self.jobID)
+            if job.failed &gt;= config.Scheduling.Options.WorkQueues.MaxTemporaryFailures:
+                # Set results to SERVICE_UNAVAILABLE
+                for ctr, result in enumerate(results):
+                    results[ctr] = (result[0], iTIPRequestStatus.SERVICE_UNAVAILABLE_CODE,)
+                returnValue(None)
+            else:
+                raise JobTemporaryError(config.Scheduling.Options.WorkQueues.TemporaryFailureDelay)
+
+
+
</ins><span class="cx"> class ScheduleWork(Record, fromTable(schema.SCHEDULE_WORK)):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A L{Record} based table whose rows are used for locking scheduling work by iCalendar UID value.
</span><span class="lines">@@ -478,6 +497,11 @@
</span><span class="cx">             if resource is not None:
</span><span class="cx">                 responses, all_delivered = self.extractSchedulingResponse(scheduler.queuedResponses)
</span><span class="cx">                 if not all_delivered:
</span><ins>+
+                    # Check for all connection failed
+                    yield self.checkTemporaryFailure(responses)
+
+                    # Update calendar data to reflect error status
</ins><span class="cx">                     calendar = (yield resource.componentForUser())
</span><span class="cx">                     changed = self.handleSchedulingResponse(responses, calendar, True)
</span><span class="cx">                     if changed:
</span><span class="lines">@@ -567,6 +591,11 @@
</span><span class="cx">             if resource is not None:
</span><span class="cx">                 responses, all_delivered = self.extractSchedulingResponse((response,))
</span><span class="cx">                 if not all_delivered:
</span><ins>+
+                    # Check for all connection failed
+                    yield self.checkTemporaryFailure(responses)
+
+                    # Update calendar data to reflect error status
</ins><span class="cx">                     calendar = (yield resource.componentForUser())
</span><span class="cx">                     changed = yield self.handleSchedulingResponse(responses, calendar, False)
</span><span class="cx">                     if changed:
</span></span></pre>
</div>
</div>

</body>
</html>