| Conditions | 9 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more |
||
| 66 | def apply_after(self, target): |
||
| 67 | target = super(ExecutionRetryPolicyApplicator, self).apply_after(target=target) |
||
| 68 | |||
| 69 | live_action_db = target |
||
| 70 | |||
| 71 | if self._is_live_action_part_of_workflow_action(live_action_db): |
||
| 72 | LOG.warning( |
||
| 73 | 'Retry cannot be applied to this liveaction because it is executed under a ' |
||
| 74 | 'workflow. Use workflow specific retry functionality where applicable. %s', |
||
| 75 | live_action_db |
||
| 76 | ) |
||
| 77 | |||
| 78 | return target |
||
| 79 | |||
| 80 | retry_count = self._get_live_action_retry_count(live_action_db=live_action_db) |
||
| 81 | |||
| 82 | extra = {'live_action_db': live_action_db, 'policy_ref': self._policy_ref, |
||
| 83 | 'retry_on': self.retry_on, 'max_retry_count': self.max_retry_count, |
||
| 84 | 'current_retry_count': retry_count} |
||
| 85 | |||
| 86 | if live_action_db.status not in VALID_RETRY_STATUSES: |
||
| 87 | # Currently we only support retrying on failed action |
||
| 88 | LOG.debug('Liveaction not in a valid retry state, not checking retry policy', |
||
| 89 | extra=extra) |
||
| 90 | return target |
||
| 91 | |||
| 92 | if (retry_count + 1) > self.max_retry_count: |
||
| 93 | LOG.info('Maximum retry count has been reached, not retrying', extra=extra) |
||
| 94 | return target |
||
| 95 | |||
| 96 | has_failed = live_action_db.status == LIVEACTION_STATUS_FAILED |
||
| 97 | has_timed_out = live_action_db.status == LIVEACTION_STATUS_TIMED_OUT |
||
| 98 | |||
| 99 | # TODO: This is not crash and restart safe, switch to using "DELAYED" |
||
| 100 | # status |
||
| 101 | if self.delay > 0: |
||
| 102 | re_run_live_action = functools.partial(eventlet.spawn_after, self.delay, |
||
| 103 | self._re_run_live_action, |
||
| 104 | live_action_db=live_action_db) |
||
| 105 | else: |
||
| 106 | re_run_live_action = functools.partial(self._re_run_live_action, |
||
| 107 | live_action_db=live_action_db) |
||
| 108 | |||
| 109 | if has_failed and self.retry_on == RetryOnPolicy.FAILURE: |
||
| 110 | extra['failure'] = True |
||
| 111 | LOG.info('Policy matched (failure), retrying action execution in %s seconds...' % |
||
| 112 | (self.delay), extra=extra) |
||
| 113 | re_run_live_action() |
||
| 114 | return target |
||
| 115 | |||
| 116 | if has_timed_out and self.retry_on == RetryOnPolicy.TIMEOUT: |
||
| 117 | extra['timeout'] = True |
||
| 118 | LOG.info('Policy matched (timeout), retrying action execution in %s seconds...' % |
||
| 119 | (self.delay), extra=extra) |
||
| 120 | re_run_live_action() |
||
| 121 | return target |
||
| 122 | |||
| 123 | return target |
||
| 124 | |||
| 168 |