Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Tryton
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tryton
Tryton
Commits
d404a49a
Commit
d404a49a
authored
6 years ago
by
Cédric Krier
Browse files
Options
Downloads
Patches
Plain Diff
Lock records when processing
issue8012 review60511002
parent
74209466
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
payment.py
+21
-0
21 additions, 0 deletions
payment.py
with
21 additions
and
0 deletions
payment.py
+
21
−
0
View file @
d404a49a
...
...
@@ -370,6 +370,7 @@
(
'
stripe_charge_id
'
,
'
=
'
,
None
),
])
for
payment
in
payments
:
cls
.
__lock
([
payment
])
try
:
charge
=
stripe
.
Charge
.
create
(
**
payment
.
_charge_parameters
())
except
(
stripe
.
error
.
RateLimitError
,
...
...
@@ -432,6 +433,7 @@
or
payment
.
stripe_captured
or
payment
.
state
!=
'
processing
'
):
continue
cls
.
__lock
([
payment
])
try
:
charge
=
stripe
.
Charge
.
retrieve
(
payment
.
stripe_charge_id
,
...
...
@@ -469,6 +471,25 @@
'
idempotency_key
'
:
idempotency_key
,
}
@classmethod
def
__lock
(
cls
,
records
):
from
trytond.tools
import
grouped_slice
,
reduce_ids
from
sql
import
Literal
,
For
transaction
=
Transaction
()
database
=
transaction
.
database
connection
=
transaction
.
connection
table
=
cls
.
__table__
()
if
database
.
has_select_for
():
for
sub_records
in
grouped_slice
(
records
):
where
=
reduce_ids
(
table
.
id
,
sub_records
)
query
=
table
.
select
(
Literal
(
1
),
where
=
where
,
for_
=
For
(
'
UPDATE
'
,
nowait
=
True
))
with
connection
.
cursor
()
as
cursor
:
cursor
.
execute
(
*
query
)
else
:
database
.
lock
(
connection
,
cls
.
_table
)
class
Account
(
ModelSQL
,
ModelView
):
"
Stripe Account
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment