当前位置: 首页>>代码示例>>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;未经允许,请勿转载。