lucid-shopify 0.61.1 → 0.62.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lucid/shopify/bulk_request.rb +45 -12
- data/lib/lucid/shopify/response.rb +5 -3
- data/lib/lucid/shopify/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e66a0c2dcd13c2a44f4200675e90d3f90199fee2a199d6be48fb52ceaffab607
|
4
|
+
data.tar.gz: f9d500101e5a5cae6a1f6d5de0eac6a737d5e4b7f83127e353db267f68d0d01a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9ef5945b9bf554b1826b028ddca3492c106d0c661f1a4ab7c4286a0daddd6d583043c239fd71c6803b14a17c18e3449dd07f9493faed5bc0098d13da73139a1
|
7
|
+
data.tar.gz: 25b6dc870fff5fbc006f1654793e1ab4a35159956c7f5361584e16ecca8ce7664c8f1254c108a40178e8682a2e81b067132e59e7f688b5365956508aea87f05f
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'lucid/shopify'
|
5
|
+
require 'timeout'
|
5
6
|
|
6
7
|
module Lucid
|
7
8
|
module Shopify
|
@@ -71,21 +72,48 @@ module Lucid
|
|
71
72
|
|
72
73
|
# Cancel the bulk operation.
|
73
74
|
def cancel
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
begin
|
76
|
+
client.post_graphql(credentials, <<~QUERY)
|
77
|
+
mutation {
|
78
|
+
bulkOperationCancel(id: "#{id}") {
|
79
|
+
userErrors {
|
80
|
+
field
|
81
|
+
message
|
82
|
+
}
|
80
83
|
}
|
81
84
|
}
|
82
|
-
|
83
|
-
|
85
|
+
QUERY
|
86
|
+
rescue Response::GraphQLClientError => e
|
87
|
+
return if e.response.error_message?([
|
88
|
+
/cannot be canceled when it is completed/,
|
89
|
+
])
|
90
|
+
|
91
|
+
raise e
|
92
|
+
end
|
84
93
|
|
85
|
-
|
86
|
-
|
94
|
+
poll_until(['CANCELED', 'COMPLETED'])
|
95
|
+
end
|
87
96
|
|
88
|
-
|
97
|
+
# Poll until operation status is met.
|
98
|
+
#
|
99
|
+
# @param statuses [Array<Regexp, String>] to terminate polling on
|
100
|
+
# @param timeout [Integer] in seconds
|
101
|
+
#
|
102
|
+
# @raise Timeout::Error
|
103
|
+
def poll_until(statuses, timeout: 60)
|
104
|
+
Timeout.timeout(timeout) do
|
105
|
+
loop do
|
106
|
+
status, _ = poll
|
107
|
+
|
108
|
+
break if statuses.any? do |expected_status|
|
109
|
+
case expected_status
|
110
|
+
when Regexp
|
111
|
+
status.match?(expected_status)
|
112
|
+
when String
|
113
|
+
status == expected_status
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
89
117
|
end
|
90
118
|
end
|
91
119
|
|
@@ -155,7 +183,12 @@ module Lucid
|
|
155
183
|
}
|
156
184
|
QUERY
|
157
185
|
|
158
|
-
|
186
|
+
case op&.fetch('status')
|
187
|
+
when 'CANCELING'
|
188
|
+
Operation.new(client, credentials, op['id']).poll_until(['CANCELED'])
|
189
|
+
when 'CREATED', 'RUNNING'
|
190
|
+
Operation.new(client, credentials, op['id']).cancel
|
191
|
+
end
|
159
192
|
|
160
193
|
id = client.post_graphql(credentials, <<~QUERY)['data']['bulkOperationRunQuery']['bulkOperation']['id']
|
161
194
|
mutation {
|
@@ -118,7 +118,7 @@ module Lucid
|
|
118
118
|
raise ShopError.new(request, self), 'Shop is frozen, awaiting payment'
|
119
119
|
when 403
|
120
120
|
# NOTE: Not sure what this one means (undocumented).
|
121
|
-
if
|
121
|
+
if error_message?(/unavailable shop/i)
|
122
122
|
raise ShopError.new(request, self), 'Shop is unavailable'
|
123
123
|
else
|
124
124
|
raise ClientError.new(request, self)
|
@@ -229,12 +229,14 @@ module Lucid
|
|
229
229
|
#
|
230
230
|
# @return [Boolean]
|
231
231
|
def error_message?(messages)
|
232
|
+
all_messages = error_messages + user_error_messages
|
233
|
+
|
232
234
|
messages.any? do |message|
|
233
235
|
case message
|
234
236
|
when Regexp
|
235
|
-
|
237
|
+
all_messages.any? { |other_message| other_message.match?(message) }
|
236
238
|
when String
|
237
|
-
|
239
|
+
all_messages.include?(message)
|
238
240
|
end
|
239
241
|
end
|
240
242
|
end
|