You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to understand if django-concurrency is a good solution for my problem.
I have two models:
class Order:
status = CharField()
class PushToMiddleware:
order = ForeignKey(Order)
the Order status has 3 values : READY_TO_PUSH, PUSHING, PUSHED, STUCK
My problem is I can only allow max 1 PushToMiddleware at any time when order is READY_TO_PUSH
My pseudocode in Gherkin syntax
GIVEN Order is READY_TO_PUSH
WHEN I want to push
THEN Order changes to PUSHING
AND followed by create a PushToMiddleware child record
AND some extra processing that includes an API Post call to a 3rd party
AND depending on the result of the API, the PushToMiddleware will be updated accordingly
AND if successful API call, the Order changes to PUSHED, else to STUCK
GIVEN Order is STUCK
WHEN the user wants to repush
THEN the Order changes to READY_TO_PUSH
In terms of state transitions:
START->READY_TO_PUSH-> PUSHING-> PUSHED->TERMINAL
START->READY_TO_PUSH-> PUSHING-> STUCK->READY_TO_PUSH (so this can be a loop)
I was wondering if i can include a conditionalversioned field on Order so that i can do a conditional create on PushToMiddleware in a single atomic transaction.
Atomic transaction when READY_TO_PUSH:
update the Order status from READY_TO_PUSH to PUSHING
create a new PushToMiddleware record
Atomic transaction when API call is successful
update the Order status from PUSHING to PUSHED
update the PushToMiddleware record with API call result
Atomic transaction when API call is failure
update the Order status from PUSHING to STUCK
update the PushToMiddleware record with API call result
My concern is the first atomic transaction because the business logic needs to ensure max 1 PushToMiddleware record when status is READY_TO_PUSH
The text was updated successfully, but these errors were encountered:
I'm trying to understand if django-concurrency is a good solution for my problem.
I have two models:
the
Order
status has 3 values :READY_TO_PUSH
,PUSHING
,PUSHED
,STUCK
My problem is I can only allow max 1
PushToMiddleware
at any time when order isREADY_TO_PUSH
My pseudocode in Gherkin syntax
GIVEN Order is READY_TO_PUSH
WHEN I want to push
THEN Order changes to PUSHING
AND followed by create a PushToMiddleware child record
AND some extra processing that includes an API Post call to a 3rd party
AND depending on the result of the API, the PushToMiddleware will be updated accordingly
AND if successful API call, the Order changes to PUSHED, else to STUCK
GIVEN Order is STUCK
WHEN the user wants to repush
THEN the Order changes to READY_TO_PUSH
In terms of state transitions:
START->
READY_TO_PUSH
->PUSHING
->PUSHED
->TERMINALSTART->
READY_TO_PUSH
->PUSHING
->STUCK
->READY_TO_PUSH
(so this can be a loop)I was wondering if i can include a conditionalversioned field on Order so that i can do a conditional create on PushToMiddleware in a single atomic transaction.
Atomic transaction when READY_TO_PUSH:
Atomic transaction when API call is successful
Atomic transaction when API call is failure
My concern is the first atomic transaction because the business logic needs to ensure max 1 PushToMiddleware record when status is READY_TO_PUSH
The text was updated successfully, but these errors were encountered: