File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,8 @@ class AddSomeData extends Actionable
147
147
{
148
148
protected $transactions = true;
149
149
150
+ protected $transaction_attempts = 3;
151
+
150
152
public function up(): void
151
153
{
152
154
// ...
Original file line number Diff line number Diff line change @@ -26,6 +26,13 @@ abstract class Actionable extends Migration implements Contract
26
26
*/
27
27
protected $ transactions = false ;
28
28
29
+ /**
30
+ * The number of attempts to execute a request within a transaction before throwing an error.
31
+ *
32
+ * @var int
33
+ */
34
+ protected $ transaction_attempts = 1 ;
35
+
29
36
/**
30
37
* Reverse the actions.
31
38
*/
@@ -55,4 +62,14 @@ public function enabledTransactions(): bool
55
62
{
56
63
return $ this ->transactions ;
57
64
}
65
+
66
+ /**
67
+ * The number of attempts to execute a request within a transaction before throwing an error.
68
+ *
69
+ * @return int
70
+ */
71
+ public function transactionAttempts (): int
72
+ {
73
+ return $ this ->transaction_attempts ;
74
+ }
58
75
}
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ protected function runMigration($migration, $method)
70
70
if ($ this ->enabledTransactions ($ migration )) {
71
71
DB ::transaction (function () use ($ migration , $ method ) {
72
72
parent ::runMigration ($ migration , $ method );
73
- });
73
+ }, $ this -> transactionAttempts ( $ migration ) );
74
74
75
75
return ;
76
76
}
@@ -93,12 +93,26 @@ protected function allowLogging($migration): bool
93
93
/**
94
94
* Whether it is necessary to call database transactions at runtime.
95
95
*
96
- * @param object $migration
96
+ * @param \Helldar\LaravelActions\Support\Actionable| object $migration
97
97
*
98
98
* @return bool
99
99
*/
100
100
protected function enabledTransactions ($ migration ): bool
101
101
{
102
102
return $ migration ->enabledTransactions ();
103
103
}
104
+
105
+ /**
106
+ * The number of attempts to execute a request within a transaction before throwing an error.
107
+ *
108
+ * @param \Helldar\LaravelActions\Support\Actionable|object $migration
109
+ *
110
+ * @return int
111
+ */
112
+ protected function transactionAttempts ($ migration ): int
113
+ {
114
+ $ value = $ migration ->transactionAttempts ();
115
+
116
+ return (int ) abs ($ value );
117
+ }
104
118
}
You can’t perform that action at this time.
0 commit comments