Add some errorhandling to tasks and states

blueprint taskflow

Change-Id: Ie4147eadb5fa436cd28663082d78fd001a7e3b81
This commit is contained in:
Endre Karlson 2013-08-27 18:07:43 +02:00
parent 117c68ee2d
commit 9d3df7ff0c
4 changed files with 24 additions and 5 deletions

View File

@ -159,7 +159,8 @@ class PGConfig(Base):
merchant_id = text
provider_id = text
is_default = bool
state = text
properties = DictType(key_type=text, value_type=property_type)
@ -172,6 +173,8 @@ class PaymentMethod(Base):
customer_id = text
provider_config_id = text
state = text
properties = DictType(key_type=text, value_type=property_type)

View File

@ -17,6 +17,7 @@
# under the License.
from billingstack import exceptions
from billingstack import tasks
from billingstack.collector import states
from billingstack.openstack.common import log
from billingstack.payment_gateway import get_provider
from billingstack.taskflow.patterns import linear_flow, threaded_flow
@ -35,6 +36,7 @@ class EntryCreateTask(tasks.RootTask):
self.storage = storage
def __call__(self, context, gateway_config):
gateway_config['state'] = states.VERIFYING
values = self.storage.create_pg_config(context, gateway_config)
return {'gateway_config': values}
@ -96,10 +98,15 @@ class BackendVerifyTask(tasks.RootTask):
def __call__(self, ctxt, gateway_config, gateway_provider):
gateway_provider_cls = get_provider[gateway_provider['name']]
gateway_provider_obj = gateway_provider_cls(gateway_config)
try:
gateway_provider_obj.verify_config()
except exceptions.ConfigurationError:
self.storage.update_pg_config(
ctxt, gateway_config['id'], {'state': states.INVALID})
raise
self.storage.update_pg_config(
ctxt, gateway_config['id'], {'state': states.ACTIVE})
def create_flow(storage, values):

View File

@ -15,7 +15,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from billingstack import exceptions
from billingstack import tasks
from billingstack.collector import states
from billingstack.openstack.common import log
from billingstack.payment_gateway import get_provider
from billingstack.taskflow.patterns import linear_flow, threaded_flow
@ -37,6 +39,7 @@ class EntryCreateTask(tasks.RootTask):
self.storage = storage
def __call__(self, ctxt, payment_method):
payment_method['state'] = states.PENDING
values = self.storage.create_payment_method(ctxt, payment_method)
return {'payment_method': values}
@ -97,9 +100,14 @@ class BackendCreateTask(tasks.RootTask):
gateway_provider_cls = get_provider(gateway_provider['name'])
gateway_provider_obj = gateway_provider_cls(gateway_config)
gateway_provider_obj.create_payment_method(
payment_method['customer_id'],
payment_method)
try:
gateway_provider_obj.create_payment_method(
payment_method['customer_id'],
payment_method)
except exceptions.BadRequest:
self.storage.update_payment_method(
ctxt, payment_method['id'], {'status': states.INVALID})
raise
def create_flow(storage, payment_method):

View File

@ -16,5 +16,6 @@
# License for the specific language governing permissions and limitations
# under the License.
PENDING = u'PENDING'
CREATED = u'CREATED'
VERIFYING = u'VERIFYING'
ACTIVE = u'ACTIVE'
INVALID = u'INVALID'