Beispiel #1
0
 def test_update_success(self):
     tasks_result = pm_organizationTasks.query_key(task_id.format(str(1)))
     updated_at = tasks_result['UpdatedAt']
     attribute = {
         'Code': {
             "Value": update_organization_task['Code']
         },
         'Target': {
             "Value": update_organization_task['Target']
         },
         'UserID': {
             "Value": update_organization_task['UserID']
         },
         'MailAddress': {
             "Value": update_organization_task['MailAddress']
         },
         'TaskStatus': {
             "Value": update_organization_task['TaskStatus']
         },
         'RetryCount': {
             "Value": update_organization_task['RetryCount']
         },
         'MaxRetry': {
             "Value": update_organization_task['MaxRetry']
         }
     }
     pm_organizationTasks.update(
         task_id.format(str(1)), attribute, updated_at)
     update_result = pm_organizationTasks.query_key(task_id.format(str(1)))
     attribute['TaskID'] = task_id.format(str(1))
     self.organizationTask_result_check(
         actual_organization=update_result,
         expected_organization=update_organization_task)
Beispiel #2
0
    def test_batch_delete_project_error_status_task(self):
        # Status = 1 Running
        event_mock = {
            'TaskId': task_id.format(str(1)),
            'Message': {
                'MessageId': 'MessageId',
                'ReceiptHandle': 'ReceiptHandle'
            }
        }
        projects.execute_delete_project_handler(event_mock, {})
        # Get data in database
        project_task = pm_organizationTasks.query_key(
            task_id.format(str(1)))
        # Check data
        self.assertEqual(project_task['TaskStatus'], Status.Error.value)

        # Status = 2 Done
        event_mock['TaskId'] = task_id.format(str(2))
        projects.execute_delete_project_handler(event_mock, {})
        # Get data in database
        project_task = pm_organizationTasks.query_key(
            task_id.format(str(2)))
        # Check data
        self.assertEqual(project_task['TaskStatus'], Status.Error.value)

        # Status = -1 ERROR and RetryCount > MaxRetry
        event_mock['TaskId'] = task_id.format(str(5))
        projects.execute_delete_project_handler(event_mock, {})
        # Get data in database
        project_task = pm_organizationTasks.query_key(
            task_id.format(str(5)))
        # Check data
        self.assertEqual(project_task['TaskStatus'], Status.Error.value)
Beispiel #3
0
 def test_query_key_success(self):
     tmp_organization_task = copy.copy(organization_task_template)
     tmp_organization_task['TaskID'] = task_id.format(str(1))
     insert_result = pm_organizationTasks.query_key(task_id.format(str(1)))
     self.organizationTask_result_check(
         actual_organization=insert_result,
         expected_organization=tmp_organization_task)
Beispiel #4
0
def check_process_status(task_id):
    pm_logger = common_utils.begin_logger(task_id, __name__,
                                          inspect.currentframe())
    organization_task = pm_organizationTasks.query_key(task_id)
    if not organization_task:
        pm_logger.info("OrganizationTasksより取得した件数が0")
        return None

    status = organization_task['TaskStatus']
    retry_count = organization_task['RetryCount']
    max_retry = organization_task['MaxRetry']
    updated_at = organization_task['UpdatedAt']

    if (status == Status.Running.value):
        pm_logger.info("処理が開始されているため、タスクの重複実行防止で処理を停止します。")
        return None

    if (status == Status.Done.value):
        pm_logger.info("すでに完了したタスクのため、処理を停止します。")
        return None

    if (status == Status.Error.value and retry_count >= max_retry):
        pm_logger.info("リトライ回数の上限に達しているため、処理を停止します。")
        return None

    attribute = {'TaskStatus': {"Value": Status.Running.value}}
    if (status == Status.Error.value and retry_count < max_retry):
        retry_count += 1
        attribute['RetryCount'] = {"Value": retry_count}
    # Update Tasks
    is_update = pm_organizationTasks.update(task_id, attribute, updated_at)
    if is_update is False:
        return None
    return organization_task['Target']
Beispiel #5
0
    def test_batch_delete_reports_susscess(self):
        # Status = 0 Waiting
        event_mock = {
            'TaskId': task_id.format(str(3)),
            'Message': {
                'MessageId': 'MessageId',
                'ReceiptHandle': 'ReceiptHandle'
            }
        }
        reports.execute_delete_report_handler(event_mock, {})
        # Get data in database
        organization_task = pm_organizationTasks.query_key(task_id.format(str(3)))
        # Check data
        self.assertEqual(int(organization_task['TaskStatus']), Status.Done.value)

        # Status = 4 ERROR and RetryCount < MaxRetry
        event_mock['TaskId'] = task_id.format(str(4))
        reports.execute_delete_report_handler(event_mock, {})
        # Get data in database
        organization_task = pm_organizationTasks.query_key(task_id.format(str(4)))
        # Check data
        self.assertEqual(organization_task['TaskStatus'], Status.Done.value)
Beispiel #6
0
 def test_batch_delete_project_error_get_reports(self):
     event_mock = {
         'TaskId': task_id.format(str(9)),
         'Message': {
             'MessageId': 'MessageId',
             'ReceiptHandle': 'ReceiptHandle'
         }
     }
     projects.execute_delete_project_handler(event_mock, {})
     # Get data in database
     project_task = pm_organizationTasks.query_key(
         task_id.format(str(9)))
     # Check data
     self.assertEqual(project_task['TaskStatus'], Status.Done.value)
Beispiel #7
0
 def test_create_success(self):
     tmp_organization_task = copy.copy(organization_task_template)
     tmp_organization_task['TaskID'] = task_id.format(str(3))
     pm_organizationTasks.create_organizationTask(
         trace_id, tmp_organization_task['TaskID'],
         tmp_organization_task['Code'],
         tmp_organization_task['Target'],
         tmp_organization_task['UserID'],
         tmp_organization_task['MailAddress'],
         tmp_organization_task['TaskStatus'],
         tmp_organization_task['RetryCount'],
         tmp_organization_task['MaxRetry'])
     insert_result = pm_organizationTasks.query_key(task_id.format(str(3)))
     self.organizationTask_result_check(
         actual_organization=insert_result,
         expected_organization=tmp_organization_task)
     pm_organizationTasks.delete(trace_id, task_id.format(str(3)))
Beispiel #8
0
    def test_batch_delete_organization_user_success_with_record_zero(self):
        # handler
        task_id_0 = task_id.format(str(0))
        event_mock = {
            'TaskId': task_id_0,
            'Message': {
                'MessageId': 'MessageId',
                'ReceiptHandle': 'ReceiptHandle'
            }
        }
        users.execute_delete_organization_user_handler(event_mock, {})

        # Get data in database
        awscoop_task = pm_organizationTasks.query_key(task_id_0)

        # Check data
        self.assertEqual(int(awscoop_task['TaskStatus']), Status.Done.value)
Beispiel #9
0
def update_status(task_id, status, message_id):
    common_utils.begin_logger(task_id, __name__, inspect.currentframe())
    organization_task = pm_organizationTasks.query_key(task_id)
    if not organization_task:
        return False

    # Update Tasks
    attribute = {
        'TaskStatus': {
            "Value": status
        },
        'MessageID': {
            "Value": message_id
        }
    }
    updated_at = organization_task['UpdatedAt']
    return pm_organizationTasks.update(task_id, attribute, updated_at)
    def test_batch_delete_organization_susscess(self):
        # handler
        event_mock = {
            'TaskId': task_id.format(str(3)),
            'Message': {
                'MessageId': 'MessageId',
                'ReceiptHandle': 'ReceiptHandle'
            }
        }
        organizations.execute_delete_organization_handler(event_mock, {})

        # Get data in database
        organization_task = pm_organizationTasks.query_key(
            task_id.format(str(3)))

        # Check data
        self.assertEqual(
            int(organization_task['TaskStatus']), Status.Done.value)
Beispiel #11
0
    def test_batch_delete_organization_user_success_with_update(self):
        # update pm_orgNotifyMailDestinaltions
        attribute = {'Destinations': {"Value": destinations_update}}
        pm_orgNotifyMailDestinations.update(trace_id,
                                            organization_id.format(3),
                                            notify_code, attribute)

        # handler
        task_id_3 = task_id.format(str(3))
        event_mock = {
            'TaskId': task_id_3,
            'Message': {
                'MessageId': 'MessageId',
                'ReceiptHandle': 'ReceiptHandle'
            }
        }
        users.execute_delete_organization_user_handler(event_mock, {})

        # Get data in database
        awscoop_task = pm_organizationTasks.query_key(task_id_3)

        # Check data
        self.assertEqual(int(awscoop_task['TaskStatus']), Status.Done.value)
Beispiel #12
0
 def test_delete_success(self):
     pm_organizationTasks.delete(trace_id, task_id.format(str(2)))
     delete_result = pm_organizationTasks.query_key(task_id.format(str(2)))
     self.assertIsNone(delete_result)