當前位置: 首頁>>代碼示例>>Python>>正文


Python iaxiom.IScheduler類代碼示例

本文整理匯總了Python中axiom.iaxiom.IScheduler的典型用法代碼示例。如果您正苦於以下問題:Python IScheduler類的具體用法?Python IScheduler怎麽用?Python IScheduler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IScheduler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_scheduler

    def test_scheduler(self):
        """
        Test that the ordering and timing of scheduled calls is correct.
        """
        # create 3 timed events.  the first one fires.  the second one fires,
        # then reschedules itself.  the third one should never fire because the
        # reactor is shut down first.  assert that the first and second fire
        # only once, and that the third never fires.
        s = self.store

        t1 = TestEvent(testCase=self,
                       name=u't1',
                       store=s, runAgain=None)
        t2 = TestEvent(testCase=self,
                       name=u't2',
                       store=s, runAgain=2)
        t3 = TestEvent(testCase=self,
                       name=u't3',
                       store=s, runAgain=None)

        now = self.now()
        self.ts = [t1, t2, t3]

        S = IScheduler(s)

        # Schedule them out of order to make sure behavior doesn't
        # depend on tasks arriving in soonest-to-latest order.
        S.schedule(t2, now + timedelta(seconds=3))
        S.schedule(t1, now + timedelta(seconds=1))
        S.schedule(t3, now + timedelta(seconds=100))

        self.clock.pump([2, 2, 2])
        self.assertEqual(t1.runCount, 1)
        self.assertEqual(t2.runCount, 2)
        self.assertEqual(t3.runCount, 0)
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:35,代碼來源:test_scheduler.py

示例2: makeScheduler

 def makeScheduler(self):
     """
     Create, install, and return a Scheduler with a fake callLater.
     """
     scheduler = IScheduler(self.store)
     scheduler.callLater = self.clock.callLater
     scheduler.now = self.now
     return scheduler
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:8,代碼來源:test_scheduler.py

示例3: _scheduleMePlease

 def _scheduleMePlease(self):
     """
     This queue needs to have its run() method invoked at some point in the
     future.  Tell the dependent scheduler to schedule it if it isn't
     already pending execution.
     """
     sched = IScheduler(self.store)
     if len(list(sched.scheduledTimes(self))) == 0:
         sched.schedule(self, sched.now())
開發者ID:fusionapp,項目名稱:mantissa,代碼行數:9,代碼來源:interstore.py

示例4: PastesAPIResource

class PastesAPIResource(Resource):
    """
    Resource for the "pastes" API.

    I{POST}ing to this resource will create a new L{Paste} item. I{GET}ting
    a child of this resource will look a L{Paste} item up by its I{name}
    attribute.
    """
    def __init__(self, store):
        self._store = store
        self._scheduler = IScheduler(self._store)
        self._chain = japaneseChain()
        Resource.__init__(self)


    def _generateName(self, n=8):
        """
        Generate a paste name.

        @type  n: L{int}
        @param n: Length of the name to generate.

        @rtype: L{unicode}
        """
        return u''.join(itertools.islice(self._chain, n))


    def _createPaste(self, content, languageHint=None):
        p = Paste(
            store=self._store,
            name=self._generateName(),
            content=content,
            languageHint=languageHint)
        # <k4y> so what's a good paste lifetime?
        # * mithrandi picks "6 days" out of a musical hat
        # <k4y> what's it playing?
        # <mithrandi> DJ Shadow - Six Days
        expiryDate = p.created + timedelta(days=6)
        self._scheduler.schedule(p, expiryDate)
        return p


    def render_POST(self, request):
        data = json.load(request.content)
        return self._createPaste(**data).toJSON()


    def getChild(self, path, request):
        try:
            paste = Paste.findByName(self._store, path.decode('ascii'))
        except ItemNotFound:
            return NoResource('No such paste')
        else:
            return Data(paste.toJSON(), 'application/json')
開發者ID:jonathanj,項目名稱:Codetip,代碼行數:54,代碼來源:resource.py

示例5: test_unscheduling

    def test_unscheduling(self):
        """
        Test the unscheduleFirst method of the scheduler.
        """
        sch = IScheduler(self.store)
        t1 = TestEvent(testCase=self, name=u't1', store=self.store)
        t2 = TestEvent(testCase=self, name=u't2', store=self.store, runAgain=None)

        sch.schedule(t1, self.now() + timedelta(seconds=1))
        sch.schedule(t2, self.now() + timedelta(seconds=2))
        sch.unscheduleFirst(t1)
        self.clock.advance(3)
        self.assertEquals(t1.runCount, 0)
        self.assertEquals(t2.runCount, 1)
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:14,代碼來源:test_scheduler.py

示例6: setUp

    def setUp(self):
        self.clock = Clock()

        self.dbdir = filepath.FilePath(self.mktemp())
        self.store = Store(self.dbdir)
        self.substoreItem = SubStore.createNew(self.store, ['sub'])
        self.substore = self.substoreItem.open()

        self.scheduler = IScheduler(self.store)
        self.subscheduler = IScheduler(self.substore)

        self.scheduler.callLater = self.clock.callLater
        self.scheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds())
        self.subscheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds())

        IService(self.store).startService()
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:16,代碼來源:test_scheduler.py

示例7: test_interface

 def test_interface(self):
     """
     L{Scheduler} provides L{IScheduler} (which it proxies) and
     L{IService} (which is a no-op).
     """
     self.assertTrue(IScheduler.providedBy(self.oldScheduler))
     self.assertTrue(IService.providedBy(self.oldScheduler))
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:7,代碼來源:test_scheduler.py

示例8: testBasicScheduledError

    def testBasicScheduledError(self):
        S = IScheduler(self.store)
        S.schedule(NotActuallyRunnable(store=self.store), self.now())

        te = TestEvent(store=self.store, testCase=self,
                       name=u't1', runAgain=None)
        S.schedule(te, self.now() + timedelta(seconds=1))

        self.assertEquals(
            self.store.query(TimedEventFailureLog).count(), 0)

        self.clock.advance(3)

        self.assertEquals(te.runCount, 1)

        errs = self.flushLoggedErrors(AttributeError)
        self.assertEquals(len(errs), 1)
        self.assertEquals(self.store.query(TimedEventFailureLog).count(), 1)
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:18,代碼來源:test_scheduler.py

示例9: testScheduledErrorWithHandler

    def testScheduledErrorWithHandler(self):
        S = IScheduler(self.store)
        spec = SpecialErrorHandler(store=self.store)
        S.schedule(spec, self.now())

        te = TestEvent(store=self.store, testCase=self,
                       name=u't1', runAgain=None)
        S.schedule(te, self.now() + timedelta(seconds=1))
        self.assertEquals(
            self.store.query(TimedEventFailureLog).count(), 0)

        self.clock.advance(3)

        self.assertEquals(te.runCount, 1)

        errs = self.flushLoggedErrors(SpecialError)
        self.assertEquals(len(errs), 1)
        self.assertEquals(self.store.query(TimedEventFailureLog).count(), 0)
        self.failUnless(spec.procd)
        self.failIf(spec.broken)
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:20,代碼來源:test_scheduler.py

示例10: test_inspection

    def test_inspection(self):
        """
        Test that the L{scheduledTimes} method returns an iterable of all the
        times at which a particular item is scheduled to run.
        """
        now = self.now() + timedelta(seconds=1)
        off = timedelta(seconds=3)
        sch = IScheduler(self.store)
        runnable = TestEvent(store=self.store, name=u'Only event')
        sch.schedule(runnable, now)
        sch.schedule(runnable, now + off)
        sch.schedule(runnable, now + off + off)

        self.assertEquals(
            list(sch.scheduledTimes(runnable)),
            [now, now + off, now + off + off])
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:16,代碼來源:test_scheduler.py

示例11: test_deletedRunnable

    def test_deletedRunnable(self):
        """
        Verify that if a scheduled item is deleted,
        L{TimedEvent.invokeRunnable} just deletes the L{TimedEvent} without
        raising an exception.
        """
        now = self.now()
        scheduler = IScheduler(self.store)
        runnable = TestEvent(store=self.store, name=u'Only event')
        scheduler.schedule(runnable, now)

        runnable.deleteFromStore()

        # Invoke it manually to avoid timing complexity.
        timedEvent = self.store.findUnique(
            TimedEvent, TimedEvent.runnable == runnable)
        timedEvent.invokeRunnable()

        self.assertEqual(
            self.store.findUnique(
                TimedEvent,
                TimedEvent.runnable == runnable,
                default=None),
            None)
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:24,代碼來源:test_scheduler.py

示例12: setUp

    def setUp(self):
        self.dbdir = FilePath(self.mktemp())
        self.store = Store(self.dbdir)
        self.ls = userbase.LoginSystem(store=self.store)
        self.scheduler = IScheduler(self.store)

        self.account = self.ls.addAccount(
            self.localpart, self.domain, 'PASSWORD')

        self.accountStore = self.account.avatars.open()

        self.ss = IScheduler(self.accountStore)

        self.origdir = self.accountStore.dbdir
        self.destdir = FilePath(self.mktemp())
開發者ID:perkinslr,項目名稱:axiom-py3,代碼行數:15,代碼來源:test_userbase.py

示例13: _schedule

 def _schedule(self, when):
     """
     Ensure that this hook is scheduled to run at or before C{when}.
     """
     sched = IScheduler(self.store)
     for scheduledAt in sched.scheduledTimes(self):
         if when < scheduledAt:
             sched.reschedule(self, scheduledAt, when)
         break
     else:
         sched.schedule(self, when)
開發者ID:twisted,項目名稱:axiom,代碼行數:11,代碼來源:scheduler.py

示例14: test_scheduledTimesDuringRun

    def test_scheduledTimesDuringRun(self):
        """
        L{Scheduler.scheduledTimes} should not include scheduled times that have
        already triggered.
        """
        futureTimes = []
        scheduler = IScheduler(self.store)
        runner = HookRunner(
            store=self.store,
            hook=lambda self: futureTimes.append(
                list(scheduler.scheduledTimes(self))))

        then = self.now() + timedelta(seconds=1)
        scheduler.schedule(runner, self.now())
        scheduler.schedule(runner, then)
        self.clock.advance(1)
        self.assertEquals(futureTimes, [[then], []])
開發者ID:ldanielburr,項目名稱:axiom,代碼行數:17,代碼來源:test_scheduler.py

示例15: SubStoreMigrationTestCase

class SubStoreMigrationTestCase(unittest.TestCase):

    IMPORTANT_VALUE = 159

    localpart = 'testuser'
    domain = 'example.com'

    def setUp(self):
        self.dbdir = FilePath(self.mktemp())
        self.store = Store(self.dbdir)
        self.ls = userbase.LoginSystem(store=self.store)
        self.scheduler = IScheduler(self.store)

        self.account = self.ls.addAccount(
            self.localpart, self.domain, 'PASSWORD')

        self.accountStore = self.account.avatars.open()

        self.ss = IScheduler(self.accountStore)

        self.origdir = self.accountStore.dbdir
        self.destdir = FilePath(self.mktemp())


    def test_extraction(self):
        """
        Ensure that user store extraction works correctly,
        particularly in the presence of timed events.
        """
        thing = ThingThatMovesAround(store=self.accountStore,
                                     superValue=self.IMPORTANT_VALUE)
        self.ss.schedule(thing, Time() + datetime.timedelta(days=1))
        self.test_noTimedEventsExtraction()


    def test_noTimedEventsExtraction(self):
        """
        Ensure that user store extraction works correctly if no timed
        events are present.
        """
        userbase.extractUserStore(self.account, self.destdir)
        self.assertEqual(
            self.ls.accountByAddress(self.localpart, self.domain),
            None)

        self.assertFalse(list(self.store.query(SubStore, SubStore.storepath == self.origdir)))
        self.origdir.restat(False)
        self.assertFalse(self.origdir.exists())
        self.assertFalse(list(self.store.query(_SubSchedulerParentHook)))


    def test_noTimedEventsInsertion(self):
        """
        Test that inserting a user store succeeds if it contains no
        timed events.
        """
        self.test_noTimedEventsExtraction()
        self._testInsertion()


    def test_insertion(self, _deleteDomainDirectory=False):
        """
        Test that inserting a user store succeeds and that the right
        items are placed in the site store as a result.
        """
        self.test_extraction()
        self._testInsertion(_deleteDomainDirectory)
        insertedStore = self.ls.accountByAddress(self.localpart,
                                                 self.domain).avatars.open()
        self.assertEqual(
            insertedStore.findUnique(ThingThatMovesAround).superValue,
            self.IMPORTANT_VALUE)
        siteStoreSubRef = self.store.getItemByID(insertedStore.idInParent)
        ssph = self.store.findUnique(_SubSchedulerParentHook,
                         _SubSchedulerParentHook.subStore == siteStoreSubRef,
                                     default=None)
        self.assertTrue(ssph)
        self.assertTrue(self.store.findUnique(TimedEvent,
                                              TimedEvent.runnable == ssph))


    def _testInsertion(self, _deleteDomainDirectory=False):
        """
        Helper method for inserting a user store.
        """
        if _deleteDomainDirectory:
            self.store.filesdir.child('account').child(self.domain).remove()

        userbase.insertUserStore(self.store, self.destdir)


    def test_insertionWithNoDomainDirectory(self):
        """
        Test that inserting a user store succeeds even if it is the
        first one in that domain to be inserted.
        """
        self.test_insertion(True)
開發者ID:perkinslr,項目名稱:axiom-py3,代碼行數:97,代碼來源:test_userbase.py


注:本文中的axiom.iaxiom.IScheduler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。