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


Python LiveAction.add_or_update方法代码示例

本文整理汇总了Python中st2common.persistence.action.LiveAction.add_or_update方法的典型用法代码示例。如果您正苦于以下问题:Python LiveAction.add_or_update方法的具体用法?Python LiveAction.add_or_update怎么用?Python LiveAction.add_or_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.persistence.action.LiveAction的用法示例。


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

示例1: test_no_retry_on_workflow_task

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_no_retry_on_workflow_task(self):
        # Verify initial state
        self.assertSequenceEqual(LiveAction.get_all(), [])
        self.assertSequenceEqual(ActionExecution.get_all(), [])

        # Start a mock action which times out
        live_action_db = LiveActionDB(
            action='wolfpack.action-1',
            parameters={'actionstr': 'foo'},
            context={'parent': {'execution_id': 'abcde'}}
        )

        live_action_db, execution_db = action_service.request(live_action_db)
        live_action_db = LiveAction.get_by_id(str(live_action_db.id))
        self.assertEqual(live_action_db.status, LIVEACTION_STATUS_REQUESTED)

        # Expire the workflow instance.
        live_action_db.status = LIVEACTION_STATUS_TIMED_OUT
        live_action_db.context['policies'] = {}
        execution_db.status = LIVEACTION_STATUS_TIMED_OUT
        LiveAction.add_or_update(live_action_db)
        ActionExecution.add_or_update(execution_db)

        # Simulate policy "apply_after" run
        self.policy.apply_after(target=live_action_db)

        # Note: There should be no new objects since live action is under the context of a workflow.
        live_action_dbs = LiveAction.get_all()
        action_execution_dbs = ActionExecution.get_all()
        self.assertEqual(len(live_action_dbs), 1)
        self.assertEqual(len(action_execution_dbs), 1)
        self.assertEqual(action_execution_dbs[0].status, LIVEACTION_STATUS_TIMED_OUT)
开发者ID:nzlosh,项目名称:st2,代码行数:34,代码来源:test_retry_policy.py

示例2: test_retry_on_timeout_max_retries_reached

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_retry_on_timeout_max_retries_reached(self):
        # Verify initial state
        self.assertSequenceEqual(LiveAction.get_all(), [])
        self.assertSequenceEqual(ActionExecution.get_all(), [])

        # Start a mock action which times out
        liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
        live_action_db, execution_db = action_service.request(liveaction)

        live_action_db.status = LIVEACTION_STATUS_TIMED_OUT
        live_action_db.context['policies'] = {}
        live_action_db.context['policies']['retry'] = {'retry_count': 2}
        execution_db.status = LIVEACTION_STATUS_TIMED_OUT
        LiveAction.add_or_update(live_action_db)
        ActionExecution.add_or_update(execution_db)

        # Simulate policy "apply_after" run
        self.policy.apply_after(target=live_action_db)

        # Note: There should be no new objects since max retries has been reached
        live_action_dbs = LiveAction.get_all()
        action_execution_dbs = ActionExecution.get_all()
        self.assertEqual(len(live_action_dbs), 1)
        self.assertEqual(len(action_execution_dbs), 1)
        self.assertEqual(action_execution_dbs[0].status, LIVEACTION_STATUS_TIMED_OUT)
开发者ID:Plexxi,项目名称:st2,代码行数:27,代码来源:test_retry_policy.py

示例3: test_no_retry_on_non_applicable_statuses

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_no_retry_on_non_applicable_statuses(self):
        # Verify initial state
        self.assertSequenceEqual(LiveAction.get_all(), [])
        self.assertSequenceEqual(ActionExecution.get_all(), [])

        # Start a mock action in various statuses in which we shouldn't retry
        non_retry_statuses = [
            LIVEACTION_STATUS_REQUESTED,
            LIVEACTION_STATUS_SCHEDULED,
            LIVEACTION_STATUS_DELAYED,
            LIVEACTION_STATUS_CANCELING,
            LIVEACTION_STATUS_CANCELED,
        ]

        action_ref = 'wolfpack.action-1'

        for status in non_retry_statuses:
            liveaction = LiveActionDB(action=action_ref, parameters={'actionstr': 'foo'})
            live_action_db, execution_db = action_service.request(liveaction)

            live_action_db.status = status
            execution_db.status = status
            LiveAction.add_or_update(live_action_db)
            ActionExecution.add_or_update(execution_db)

            # Simulate policy "apply_after" run
            self.policy.apply_after(target=live_action_db)

        # None of the actions should have been retried
        live_action_dbs = LiveAction.get_all()
        action_execution_dbs = ActionExecution.get_all()
        self.assertEqual(len(live_action_dbs), len(non_retry_statuses))
        self.assertEqual(len(action_execution_dbs), len(non_retry_statuses))
开发者ID:nzlosh,项目名称:st2,代码行数:35,代码来源:test_retry_policy.py

示例4: test_retry_on_timeout_first_retry_is_successful

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_retry_on_timeout_first_retry_is_successful(self):
        # Verify initial state
        self.assertSequenceEqual(LiveAction.get_all(), [])
        self.assertSequenceEqual(ActionExecution.get_all(), [])

        # Start a mock action which times out
        liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
        live_action_db, execution_db = action_service.request(liveaction)

        live_action_db.status = LIVEACTION_STATUS_TIMED_OUT
        execution_db.status = LIVEACTION_STATUS_TIMED_OUT
        LiveAction.add_or_update(live_action_db)
        ActionExecution.add_or_update(execution_db)

        # Simulate policy "apply_after" run
        self.policy.apply_after(target=live_action_db)

        # There should be two objects - original execution and retried execution
        live_action_dbs = LiveAction.get_all()
        action_execution_dbs = ActionExecution.get_all()
        self.assertEqual(len(live_action_dbs), 2)
        self.assertEqual(len(action_execution_dbs), 2)
        self.assertEqual(action_execution_dbs[0].status, LIVEACTION_STATUS_TIMED_OUT)
        self.assertEqual(action_execution_dbs[1].status, LIVEACTION_STATUS_REQUESTED)

        # Verify retried execution contains policy related context
        original_liveaction_id = action_execution_dbs[0].liveaction['id']

        context = action_execution_dbs[1].context
        self.assertTrue('policies' in context)
        self.assertEqual(context['policies']['retry']['retry_count'], 1)
        self.assertEqual(context['policies']['retry']['applied_policy'], 'test_policy')
        self.assertEqual(context['policies']['retry']['retried_liveaction_id'],
                         original_liveaction_id)

        # Simulate success of second action so no it shouldn't be retried anymore
        live_action_db = live_action_dbs[1]
        live_action_db.status = LIVEACTION_STATUS_SUCCEEDED
        LiveAction.add_or_update(live_action_db)

        # Simulate policy "apply_after" run
        self.policy.apply_after(target=live_action_db)

        # There should be no new object since action succeeds so no retry was attempted
        live_action_dbs = LiveAction.get_all()
        action_execution_dbs = ActionExecution.get_all()
        self.assertEqual(len(live_action_dbs), 2)
        self.assertEqual(len(action_execution_dbs), 2)
        self.assertEqual(live_action_dbs[0].status, LIVEACTION_STATUS_TIMED_OUT)
        self.assertEqual(live_action_dbs[1].status, LIVEACTION_STATUS_SUCCEEDED)
开发者ID:Plexxi,项目名称:st2,代码行数:52,代码来源:test_retry_policy.py

示例5: delete

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def delete(self, exec_id):
        """
        Stops a single execution.

        Handles requests:
            DELETE /actionexecutions/<id>

        """
        execution_api = self._get_one(id=exec_id)

        if not execution_api:
            abort(http_client.NOT_FOUND, 'Execution with id %s not found.' % exec_id)
            return

        liveaction_id = execution_api.liveaction['id']
        if not liveaction_id:
            abort(http_client.INTERNAL_SERVER_ERROR,
                  'Execution object missing link to liveaction %s.' % liveaction_id)

        try:
            liveaction_db = LiveAction.get_by_id(liveaction_id)
        except:
            abort(http_client.INTERNAL_SERVER_ERROR,
                  'Execution object missing link to liveaction %s.' % liveaction_id)
            return

        if liveaction_db.status == LIVEACTION_STATUS_CANCELED:
            abort(http_client.OK,
                  'Action is already in "canceled" state.')

        if liveaction_db.status not in CANCELABLE_STATES:
            abort(http_client.OK,
                  'Action cannot be canceled. State = %s.' % liveaction_db.status)
            return

        liveaction_db.status = 'canceled'
        liveaction_db.end_timestamp = isotime.add_utc_tz(datetime.datetime.utcnow())
        liveaction_db.result = {'message': 'Action canceled by user.'}
        try:
            LiveAction.add_or_update(liveaction_db)
        except:
            LOG.exception('Failed updating status to canceled for liveaction %s.',
                          liveaction_db.id)
            abort(http_client.INTERNAL_SERVER_ERROR, 'Failed canceling execution.')
            return

        execution_db = execution_service.update_execution(liveaction_db)
        return ActionExecutionAPI.from_model(execution_db)
开发者ID:ravidsinghbiz,项目名称:st2,代码行数:50,代码来源:actionexecutions.py

示例6: setup_action_models

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def setup_action_models(cls):
        action_db = ActionDB()
        action_db.name = 'action-1'
        action_db.description = 'awesomeness'
        action_db.enabled = True
        action_db.pack = 'wolfpack'
        action_db.ref = ResourceReference(name=action_db.name, pack=action_db.pack).ref
        action_db.entry_point = ''
        action_db.runner_type = {'name': 'test-runner'}
        action_db.parameters = {
            'actionstr': {'type': 'string', 'position': 1, 'required': True},
            'actionint': {'type': 'number', 'default': 10, 'position': 0},
            'runnerdummy': {'type': 'string', 'default': 'actiondummy'}
        }
        ActionDBUtilsTestCase.action_db = Action.add_or_update(action_db)

        liveaction_db = LiveActionDB()
        liveaction_db.status = 'initializing'
        liveaction_db.start_timestamp = datetime.datetime.utcnow()
        liveaction_db.action = ActionDBUtilsTestCase.action_db.ref
        params = {
            'actionstr': 'foo',
            'some_key_that_aint_exist_in_action_or_runner': 'bar',
            'runnerint': 555
        }
        liveaction_db.parameters = params
        ActionDBUtilsTestCase.liveaction_db = LiveAction.add_or_update(liveaction_db)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:29,代码来源:test_action_db_utils.py

示例7: test_execution_creation_action_triggered_by_rule

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
 def test_execution_creation_action_triggered_by_rule(self):
     # Wait for the action execution to complete and then confirm outcome.
     trigger_type = self.MODELS['triggertypes']['triggertype2.json']
     trigger = self.MODELS['triggers']['trigger2.json']
     trigger_instance = self.MODELS['triggerinstances']['trigger_instance_1.json']
     test_liveaction = self.FIXTURES['liveactions']['liveaction3.json']
     rule = self.MODELS['rules']['rule3.json']
     # Setup LiveAction to point to right rule and trigger_instance.
     # XXX: We need support for dynamic fixtures.
     test_liveaction['context']['rule']['id'] = str(rule.id)
     test_liveaction['context']['trigger_instance']['id'] = str(trigger_instance.id)
     test_liveaction_api = LiveActionAPI(**test_liveaction)
     test_liveaction = LiveAction.add_or_update(LiveActionAPI.to_model(test_liveaction_api))
     liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
     self.assertIsNotNone(liveaction)
     self.assertEqual(liveaction.status, LIVEACTION_STATUS_SCHEDULED)
     executions_util.create_execution_object(liveaction)
     execution = self._get_action_execution(liveaction__id=str(liveaction.id),
                                            raise_exception=True)
     self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
     self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
     self.assertDictEqual(execution.trigger_instance,
                          vars(TriggerInstanceAPI.from_model(trigger_instance)))
     self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
     action = action_utils.get_action_by_ref(liveaction.action)
     self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
     runner = RunnerType.get_by_name(action.runner_type['name'])
     self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
     liveaction = LiveAction.get_by_id(str(liveaction.id))
     self.assertEquals(execution.liveaction['id'], str(liveaction.id))
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:32,代码来源:test_executions_util.py

示例8: _update_action_results

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
 def _update_action_results(self, execution_id, status, results):
     liveaction_db = LiveAction.get_by_id(execution_id)
     if not liveaction_db:
         raise Exception('No DB model for liveaction_id: %s' % execution_id)
     liveaction_db.result = results
     liveaction_db.status = status
     # update liveaction, update actionexecution and then publish update.
     updated_liveaction = LiveAction.add_or_update(liveaction_db, publish=False)
     executions.update_execution(updated_liveaction)
     LiveAction.publish_update(updated_liveaction)
     return updated_liveaction
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:13,代码来源:base.py

示例9: test_dispatch_runner_failure

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
 def test_dispatch_runner_failure(self):
     runner_container = get_runner_container()
     params = {
         'actionstr': 'bar'
     }
     liveaction_db = self._get_failingaction_exec_db_model(params)
     liveaction_db = LiveAction.add_or_update(liveaction_db)
     executions.create_execution_object(liveaction_db)
     runner_container.dispatch(liveaction_db)
     # pickup updated liveaction_db
     liveaction_db = LiveAction.get_by_id(liveaction_db.id)
     self.assertTrue('message' in liveaction_db.result)
     self.assertTrue('traceback' in liveaction_db.result)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:15,代码来源:test_runner_container.py

示例10: test_dispatch_override_default_action_params

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
 def test_dispatch_override_default_action_params(self):
     runner_container = get_runner_container()
     params = {
         'actionstr': 'foo',
         'actionint': 20
     }
     liveaction_db = self._get_action_exec_db_model(RunnerContainerTest.action_db, params)
     liveaction_db = LiveAction.add_or_update(liveaction_db)
     executions.create_execution_object(liveaction_db)
     # Assert that execution ran successfully.
     runner_container.dispatch(liveaction_db)
     liveaction_db = LiveAction.get_by_id(liveaction_db.id)
     result = liveaction_db.result
     self.assertTrue(result.get('action_params').get('actionint') == 20)
     self.assertTrue(result.get('action_params').get('actionstr') == 'foo')
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:17,代码来源:test_runner_container.py

示例11: test_retry_on_timeout_no_retry_since_no_timeout_reached

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_retry_on_timeout_no_retry_since_no_timeout_reached(self):
        # Verify initial state
        self.assertSequenceEqual(LiveAction.get_all(), [])
        self.assertSequenceEqual(ActionExecution.get_all(), [])

        # Start a mock action which succeeds
        liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
        live_action_db, execution_db = action_service.request(liveaction)

        live_action_db.status = LIVEACTION_STATUS_SUCCEEDED
        execution_db.status = LIVEACTION_STATUS_SUCCEEDED
        LiveAction.add_or_update(live_action_db)
        ActionExecution.add_or_update(execution_db)

        # Simulate policy "apply_after" run
        self.policy.apply_after(target=live_action_db)

        # There should only be 1 object since the action didn't timeout and therefore it wasn't
        # retried
        live_action_dbs = LiveAction.get_all()
        action_execution_dbs = ActionExecution.get_all()
        self.assertEqual(len(live_action_dbs), 1)
        self.assertEqual(len(action_execution_dbs), 1)
        self.assertEqual(action_execution_dbs[0].status, LIVEACTION_STATUS_SUCCEEDED)
开发者ID:Plexxi,项目名称:st2,代码行数:26,代码来源:test_retry_policy.py

示例12: test_delayed_executions_recovery_before_timeout

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_delayed_executions_recovery_before_timeout(self):
        # Create a live action that's delayed but has not passed the timeout.
        liveaction = LiveActionDB(action='wolfpack.action-1',
                                  parameters={'actionstr': 'foo'},
                                  start_timestamp=date_utils.get_datetime_utc_now(),
                                  status=action_constants.LIVEACTION_STATUS_DELAYED)

        liveaction = LiveAction.add_or_update(liveaction, publish=False)
        executions.create_execution_object(liveaction, publish=False)

        # Run the rescheduling routine.
        scheduler.recover_delayed_executions()

        # The live action is expected to stay "delayed".
        liveaction = LiveAction.get_by_id(str(liveaction.id))
        self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_DELAYED)
开发者ID:meirwah,项目名称:st2,代码行数:18,代码来源:test_scheduler.py

示例13: test_update_LiveAction_status_invalid

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_update_LiveAction_status_invalid(self):
        liveaction_db = LiveActionDB()
        liveaction_db.status = 'initializing'
        liveaction_db.start_timestamp = datetime.datetime.utcnow()
        liveaction_db.action = ResourceReference(
            name=ActionDBUtilsTestCase.action_db.name,
            pack=ActionDBUtilsTestCase.action_db.pack).ref
        params = {
            'actionstr': 'foo',
            'some_key_that_aint_exist_in_action_or_runner': 'bar',
            'runnerint': 555
        }
        liveaction_db.parameters = params
        liveaction_db = LiveAction.add_or_update(liveaction_db)

        # Update by id.
        self.assertRaises(ValueError, action_db_utils.update_liveaction_status,
                          status='mea culpa', liveaction_id=liveaction_db.id)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:20,代码来源:test_action_db_utils.py

示例14: update_liveaction_status

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
def update_liveaction_status(status=None, result=None, context=None, end_timestamp=None,
                             liveaction_id=None, runner_info=None, liveaction_db=None):
    """
        Update the status of the specified LiveAction to the value provided in
        new_status.

        The LiveAction may be specified using either liveaction_id, or as an
        liveaction_db instance.
    """

    if (liveaction_id is None) and (liveaction_db is None):
        raise ValueError('Must specify an liveaction_id or an liveaction_db when '
                         'calling update_LiveAction_status')

    if liveaction_db is None:
        liveaction_db = get_liveaction_by_id(liveaction_id)

    if status not in LIVEACTION_STATUSES:
        raise ValueError('Attempting to set status for LiveAction "%s" '
                         'to unknown status string. Unknown status is "%s"',
                         liveaction_db, status)

    LOG.debug('Updating ActionExection: "%s" with status="%s"', liveaction_db, status)
    liveaction_db.status = status

    if result:
        liveaction_db.result = result

    if context:
        liveaction_db.context.update(context)

    if end_timestamp:
        liveaction_db.end_timestamp = end_timestamp

    if runner_info:
        liveaction_db.runner_info = runner_info

    liveaction_db = LiveAction.add_or_update(liveaction_db)

    LOG.debug('Updated status for LiveAction object: %s', liveaction_db)

    return liveaction_db
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:44,代码来源:action_db.py

示例15: test_delayed_executions_recovery

# 需要导入模块: from st2common.persistence.action import LiveAction [as 别名]
# 或者: from st2common.persistence.action.LiveAction import add_or_update [as 别名]
    def test_delayed_executions_recovery(self):
        # Create a live action that's already delayed pass the allowed timeout.
        dt_now = date_utils.get_datetime_utc_now()
        dt_delta = datetime.timedelta(seconds=cfg.CONF.scheduler.delayed_execution_recovery)
        dt_timeout = dt_now - dt_delta

        liveaction = LiveActionDB(action='wolfpack.action-1',
                                  parameters={'actionstr': 'foo'},
                                  start_timestamp=dt_timeout,
                                  status=action_constants.LIVEACTION_STATUS_DELAYED)

        liveaction = LiveAction.add_or_update(liveaction, publish=False)
        executions.create_execution_object(liveaction, publish=False)

        # Run the rescheduling routine.
        scheduler.recover_delayed_executions()

        # The live action is expected to complete.
        liveaction = LiveAction.get_by_id(str(liveaction.id))
        self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
开发者ID:meirwah,项目名称:st2,代码行数:22,代码来源:test_scheduler.py


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