Exemplo n.º 1
0
    def test_status_message(self):
        pd = ProgressData(func_name='test_func_5', unique_id='plokij')
        pd.total = 42
        pd.step('Stepping')

        self.assertEqual(pd.result()['total'], 42)
        self.assertEqual(pd.result()['status_message'], 'Stepping')
Exemplo n.º 2
0
    def test_init_by_data(self):
        pd = ProgressData(func_name='test_func_3', unique_id='ghi789')
        pd.total = 100
        self.assertEqual(pd.key, ':1:SEED:test_func_3:PROG:ghi789')

        pd2 = ProgressData.from_key(pd.key)
        self.assertDictEqual(pd.data, pd2.data)
Exemplo n.º 3
0
def delete_organization_inventory(org_pk,
                                  prog_key=None,
                                  chunk_size=100,
                                  *args,
                                  **kwargs):
    """Deletes all properties & taxlots within an organization."""
    sys.setrecursionlimit(5000)  # default is 1000

    progress_data = ProgressData.from_key(
        prog_key) if prog_key else ProgressData(
            func_name='delete_organization_inventory', unique_id=org_pk)

    property_ids = list(
        Property.objects.filter(organization_id=org_pk).values_list('id',
                                                                    flat=True))
    property_state_ids = list(
        PropertyState.objects.filter(organization_id=org_pk).values_list(
            'id', flat=True))
    taxlot_ids = list(
        TaxLot.objects.filter(organization_id=org_pk).values_list('id',
                                                                  flat=True))
    taxlot_state_ids = list(
        TaxLotState.objects.filter(organization_id=org_pk).values_list(
            'id', flat=True))

    total = len(property_ids) + len(property_state_ids) + len(
        taxlot_ids) + len(taxlot_state_ids)

    if total == 0:
        return progress_data.finish_with_success(
            'No inventory data to remove for organization')

    # total steps is the total number of properties divided by the chunk size
    progress_data.total = total / float(chunk_size)
    progress_data.save()

    tasks = []
    # we could also use .s instead of .subtask and not wrap the *args
    for del_ids in batch(property_ids, chunk_size):
        tasks.append(
            _delete_organization_property_chunk.subtask(
                (del_ids, progress_data.key, org_pk)))
    for del_ids in batch(property_state_ids, chunk_size):
        tasks.append(
            _delete_organization_property_state_chunk.subtask(
                (del_ids, progress_data.key, org_pk)))
    for del_ids in batch(taxlot_ids, chunk_size):
        tasks.append(
            _delete_organization_taxlot_chunk.subtask(
                (del_ids, progress_data.key, org_pk)))
    for del_ids in batch(taxlot_state_ids, chunk_size):
        tasks.append(
            _delete_organization_taxlot_state_chunk.subtask(
                (del_ids, progress_data.key, org_pk)))
    chord(tasks,
          interval=15)(_finish_delete.subtask([org_pk, progress_data.key]))

    return progress_data.result()
Exemplo n.º 4
0
    def test_delete_cache(self):
        pd = ProgressData(func_name='test_func_4', unique_id='1q2w3e')
        pd.total = 525600
        pd.data['status'] = 'doing-something'
        pd.save()

        self.assertEqual(pd.result()['total'], 525600)
        self.assertEqual(pd.data['status'], 'doing-something')
        self.assertEqual(pd.delete()['total'], None)
Exemplo n.º 5
0
    def test_summary(self):
        pd = ProgressData(func_name='test_func_6', unique_id='pokemon')
        self.assertIsNone(pd.summary())

        new_summary = {"Values": ["As", "A", "List"]}
        pd.update_summary(new_summary)
        self.assertEqual(pd.summary(), new_summary)

        pd.step(new_summary=4815162342)
        self.assertEqual(pd.summary(), 4815162342)
Exemplo n.º 6
0
def delete_organization(org_pk):
    """delete_organization_buildings"""
    progress_data = ProgressData(func_name='delete_organization',
                                 unique_id=org_pk)

    chain(delete_organization_inventory.si(org_pk, progress_data.key),
          _delete_organization_related_data.si(org_pk, progress_data.key),
          _finish_delete.si(None, org_pk, progress_data.key))()

    return progress_data.result()
Exemplo n.º 7
0
    def _start_whole_org_match_merge_link(self, org_id, state_class_name, proposed_columns=[]):
        identifier = randint(100, 100000)
        result_key = _get_match_merge_link_key(identifier)
        set_cache_raw(result_key, {})

        progress_data = ProgressData(func_name='org_match_merge_link', unique_id=identifier)
        progress_data.delete()

        whole_org_match_merge_link.apply_async(
            args=(org_id, state_class_name, proposed_columns),
            link=cache_match_merge_link_result.s(identifier, progress_data.key)
        )

        return progress_data.key
Exemplo n.º 8
0
    def test_status_message(self):
        pd = ProgressData(func_name='test_func_5', unique_id='plokij')
        pd.total = 42
        pd.step('Stepping')

        self.assertEqual(pd.result()['total'], 42)
        self.assertEqual(pd.result()['status_message'], 'Stepping')

        # if we call step again, then the status message should not change
        pd.step()
        self.assertEqual(pd.result()['status_message'], 'Stepping')

        # Now passing in empty string will reset
        pd.step('')
        self.assertEqual(pd.result()['status_message'], '')
Exemplo n.º 9
0
    def test_create_progress(self):
        pd = ProgressData(func_name='test_func', unique_id='abc123')

        self.assertEqual(pd.key, ':1:SEED:test_func:PROG:abc123')

        data_eql = {
            'status': 'not-started',
            'status_message': '',
            'stacktrace': None,
            'func_name': 'test_func',
            'progress_key': ':1:SEED:test_func:PROG:abc123',
            'progress': 0,
            'message': None,
            'total': None,
            'unique_id': 'abc123',
        }
        self.assertEqual(pd.data['status'], 'not-started')
        self.assertDictEqual(pd.data, data_eql)
        self.assertEqual(pd.total, None)
Exemplo n.º 10
0
 def test_total_progress(self):
     pd = ProgressData(func_name='test_func_2', unique_id='def456')
     pd.total = 10
     self.assertEqual(pd.increment_value(), 10)