当前位置: 首页>>代码示例>>Python>>正文


Python models.RepeatRecord类代码示例

本文整理汇总了Python中corehq.apps.repeaters.models.RepeatRecord的典型用法代码示例。如果您正苦于以下问题:Python RepeatRecord类的具体用法?Python RepeatRecord怎么用?Python RepeatRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RepeatRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_repeater_failed_sends

    def test_repeater_failed_sends(self):
        """
        This tests records that fail to send three times
        """
        def now():
            return datetime.utcnow()

        repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
        self.assertEqual(len(repeat_records), 2)

        for repeat_record in repeat_records:
            with patch(
                    'corehq.apps.repeaters.models.simple_post_with_cached_timeout',
                    return_value=MockResponse(status_code=404)) as mock_post:
                repeat_record.fire()
                self.assertEqual(mock_post.call_count, 3)
            repeat_record.save()

        next_check_time = now() + timedelta(minutes=60)

        repeat_records = RepeatRecord.all(
            domain=self.domain,
            due_before=now() + timedelta(minutes=15),
        )
        self.assertEqual(len(repeat_records), 0)

        repeat_records = RepeatRecord.all(
            domain=self.domain,
            due_before=next_check_time,
        )
        self.assertEqual(len(repeat_records), 2)
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:31,代码来源:test_repeater.py

示例2: test_update_failure_next_check

    def test_update_failure_next_check(self):
        now = datetime.utcnow()
        record = RepeatRecord(domain=self.domain, next_check=now)
        self.assertIsNone(record.last_checked)

        record.update_failure()
        self.assertTrue(record.last_checked > now)
        self.assertEqual(record.next_check, record.last_checked + MIN_RETRY_WAIT)
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:8,代码来源:test_repeater.py

示例3: testLocks

 def testLocks(self):
     r = RepeatRecord(domain='test')
     r.save()
     r2 = RepeatRecord.get(r._id)
     self.assertTrue(r.acquire_lock(datetime.utcnow()))
     r3 = RepeatRecord.get(r._id)
     self.assertFalse(r2.acquire_lock(datetime.utcnow()))
     self.assertFalse(r3.acquire_lock(datetime.utcnow()))
     r.release_lock()
     r4 = RepeatRecord.get(r._id)
     self.assertTrue(r4.acquire_lock(datetime.utcnow()))
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:11,代码来源:test_repeater.py

示例4: tearDown

 def tearDown(self):
     self.case_repeater.delete()
     self.form_repeater.delete()
     XFormInstance.get(instance_id).delete()
     repeat_records = RepeatRecord.all()
     for repeat_record in repeat_records:
         repeat_record.delete()
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:7,代码来源:test_repeater.py

示例5: check_repeaters

def check_repeaters(request, domain):
    if request.method == 'GET':
        return HttpResponse(PAGE % {'status': '', 'domain': domain})
    elif request.method == 'POST':
        start = datetime.utcnow()
        repeat_records = RepeatRecord.all(domain, due_before=start, limit=100)
        process_repeater_list(repeat_records)
        return HttpResponse(PAGE % {'status': 'Done', 'domain': domain})
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:8,代码来源:views.py

示例6: post

 def post(self, request, domain):
     # Retriggers a repeat record
     record = RepeatRecord.get(request.POST.get('record_id'))
     record.fire(max_tries=1, force_send=True)
     record.save()
     return json_response({
         'success': record.succeeded,
         'failure_reason': record.failure_reason,
     })
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:9,代码来源:views.py

示例7: test_process_repeat_record_locking

    def test_process_repeat_record_locking(self):
        self.assertEqual(len(RepeatRecord.all()), 2)

        with patch('corehq.apps.repeaters.tasks.process_repeat_record') as mock_process:
            check_repeaters()
            self.assertEqual(mock_process.delay.call_count, 2)

        with patch('corehq.apps.repeaters.tasks.process_repeat_record') as mock_process:
            check_repeaters()
            self.assertEqual(mock_process.delay.call_count, 0)

        records = RepeatRecord.all()
        # Saving should unlock them again by changing the rev
        for record in records:
            record.save()

        with patch('corehq.apps.repeaters.tasks.process_repeat_record') as mock_process:
            check_repeaters()
            self.assertEqual(mock_process.delay.call_count, 2)
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:19,代码来源:test_repeater.py

示例8: test_check_repeat_records

    def test_check_repeat_records(self):
        self.assertEqual(len(RepeatRecord.all()), 2)

        with patch('corehq.apps.repeaters.models.simple_post_with_cached_timeout') as mock_fire:
            check_repeaters()
            self.assertEqual(mock_fire.call_count, 2)

        with patch('corehq.apps.repeaters.models.simple_post_with_cached_timeout') as mock_fire:
            check_repeaters()
            self.assertEqual(mock_fire.call_count, 0)
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:10,代码来源:test_repeater.py

示例9: handle

    def handle(self, *args, **options):
        if len(args) == 1:
            domain = args[0]
        else:
            raise CommandError('Usage: %s\n%s' % (self.args, self.help))

        next_year = datetime.datetime.utcnow() + datetime.timedelta(days=365)
        records = RepeatRecord.all(domain=domain, due_before=next_year)
        for record in records:
            record.fire(post_fn=simple_post)
            record.save()
            print '{} {}'.format(record._id, 'successful' if record.succeeded else 'failed')
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:12,代码来源:fire_repeaters.py

示例10: test_ignore_document

    def test_ignore_document(self):
        """
        When get_payload raises IgnoreDocument, fire should call update_success
        """
        repeat_records = RepeatRecord.all(
            domain=self.domain,
        )
        for repeat_record_ in repeat_records:
            repeat_record_.fire()

            self.assertIsNone(repeat_record_.next_check)
            self.assertTrue(repeat_record_.succeeded)
开发者ID:,项目名称:,代码行数:12,代码来源:

示例11: test_repeater_successful_send

    def test_repeater_successful_send(self):

        repeat_records = RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow())
        mocked_responses = [
            MockResponse(status_code=404, reason='Not Found'),
            MockResponse(status_code=200, reason='No Reason')
        ]
        for repeat_record in repeat_records:
            with patch(
                    'corehq.apps.repeaters.models.simple_post_with_cached_timeout',
                    side_effect=mocked_responses) as mock_post:
                repeat_record.fire()
                self.assertEqual(mock_post.call_count, 2)
                mock_post.assert_any_call(
                    repeat_record.get_payload(),
                    repeat_record.repeater.get_url(repeat_record),
                    headers=repeat_record.repeater.get_headers(repeat_record),
                    force_send=False,
                    timeout=POST_TIMEOUT,
                )
            repeat_record.save()

        # The following is pretty fickle and depends on which of
        #   - corehq.apps.repeaters.signals
        #   - casexml.apps.case.signals
        # gets loaded first.
        # This is deterministic but easily affected by minor code changes
        repeat_records = RepeatRecord.all(
            domain=self.domain,
            due_before=datetime.utcnow(),
        )
        for repeat_record in repeat_records:
            self.assertEqual(repeat_record.succeeded, True)
            self.assertEqual(repeat_record.next_check, None)

        self.assertEqual(len(self.repeat_records(self.domain)), 0)

        self.post_xml(self.update_xform_xml, self.domain)
        self.assertEqual(len(self.repeat_records(self.domain)), 2)
开发者ID:,项目名称:,代码行数:39,代码来源:

示例12: test_repeat_record_created

    def test_repeat_record_created(self):
        '''
        Tests that whenever an application with a repeater is saved that a repeat record is created.
        '''
        application = Application(domain=self.domain)
        application.save()

        repeat_records = RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow())
        self.assertEqual(len(repeat_records), 0)
        
        app_structure_repeater = AppStructureRepeater(domain=self.domain, url=self.forwarding_url)
        app_structure_repeater.save()

        application.save()
        repeat_records = RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow())

        self.assertEqual(len(repeat_records), 1)
        for repeat_record in repeat_records:
                self.assertEqual(repeat_record.url, self.forwarding_url)
                self.assertEqual(repeat_record.get_payload(), application.get_id)
                repeat_record.delete()
        
        application.delete()
        app_structure_repeater.delete()
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:24,代码来源:test_repeater.py

示例13: loop

 def loop():
     # take LIMIT records off the top
     # the assumption is that they all get 'popped' in the for loop
     # the only exception I can see is if there's a problem with the
     # locking, a large number of locked tasks could pile up at the top,
     # so make a provision for that worst case
     number_locked = progress_report['number_locked']
     repeat_records = RepeatRecord.all(
         due_before=start,
         limit=LIMIT + number_locked
     )
     return process_repeater_list(
         repeat_records,
         start=start,
         cutoff=start + CHECK_REPEATERS_INTERVAL,
         progress_report=progress_report
     )
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:17,代码来源:tasks.py

示例14: test_ignore_document

    def test_ignore_document(self):
        """
        When get_payload raises IgnoreDocument, fire should call update_success
        """

        @RegisterGenerator(FormRepeater, 'new_format', 'XML')
        class NewFormGenerator(BasePayloadGenerator):
            def get_payload(self, repeat_record, payload_doc):
                raise IgnoreDocument

        repeat_records = RepeatRecord.all(
            domain=self.domain,
        )
        for repeat_record_ in repeat_records:
            repeat_record_.fire()

            self.assertIsNone(repeat_record_.next_check)
            self.assertTrue(repeat_record_.succeeded)
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:18,代码来源:test_repeater.py

示例15: get

    def get(self, request, domain):
        record = RepeatRecord.get(request.GET.get('record_id'))
        content_type = record.repeater.get_payload_generator(
            record.repeater.format_or_default_format()
        ).content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return json_response({
                'error': u'Odd, could not find payload for: {}'.format(record.payload_id)
            }, status_code=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)

        return json_response({
            'payload': payload,
            'content_type': content_type,
        })
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:19,代码来源:views.py


注:本文中的corehq.apps.repeaters.models.RepeatRecord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。