Skip to content

Commit 7276ce7

Browse files
authored
fix: Use deleteHooks() method when shutting down (#32)
* fix: Use deleteHooks() method when shutting down * lint project * update dependencies * Update .codecov.yml * Change configure to parseServerSwiftConfigure * update delete hooks * Update .codecov.yml
1 parent 9ee15af commit 7276ce7

File tree

15 files changed

+148
-85
lines changed

15 files changed

+148
-85
lines changed

.codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ coverage:
44
status:
55
patch:
66
default:
7-
target: auto
7+
target: 46
88
changes: false
99
project:
1010
default:

.github/workflows/ci.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ jobs:
2121
- uses: actions/checkout@v3
2222
- name: Use multiple cores
2323
run: defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
24+
- name: Lint
25+
run: set -o pipefail && env NSUnbufferedIO=YES swiftlint --strict
2426
- name: Build and Test
25-
run: swift test --enable-code-coverage
27+
run: set -o pipefail && env NSUnbufferedIO=YES swift test --enable-code-coverage | xcpretty -c
2628
env:
2729
DEVELOPER_DIR: ${{ env.CI_XCODE }}
2830
- name: Prepare codecov
@@ -51,7 +53,7 @@ jobs:
5153
release-version: "5.7"
5254
github-token: ${{ secrets.GITHUB_TOKEN }}
5355
- name: Build and Test
54-
run: swift test --enable-test-discovery --enable-code-coverage
56+
run: set -o pipefail && env NSUnbufferedIO=YES swift test --enable-test-discovery --enable-code-coverage
5557
- name: Update codecov config
5658
run: cat .codecov.yml | curl --data-binary @- https://codecov.io/validate
5759
- name: Prepare codecov

.swiftlint.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
disabled_rules:
2+
- file_length
3+
- identifier_name
4+
- blanket_disable_command
5+
excluded: # paths to ignore during linting. Takes precedence over `included`.
6+
- DerivedData
7+
- .build
8+
- .dependencies

Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"kind" : "remoteSourceControl",
4242
"location" : "https://github.com/netreconlab/Parse-Swift.git",
4343
"state" : {
44-
"revision" : "0902da8b34cd11d6ba69e04d208d5a8505f0be9d",
45-
"version" : "5.6.0"
44+
"revision" : "8ae529657e32d4b65c8c429dc5296ab865c4721d",
45+
"version" : "5.7.0"
4646
}
4747
},
4848
{

Package.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// swift-tools-version:5.6
22
import PackageDescription
33

4+
// swiftlint:disable line_length
5+
46
let package = Package(
57
name: "ParseServerSwift",
68
platforms: [
@@ -16,7 +18,7 @@ let package = Package(
1618
dependencies: [
1719
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.76.2")),
1820
.package(url: "https://github.com/netreconlab/Parse-Swift.git",
19-
.upToNextMajor(from: "5.6.0")),
21+
.upToNextMajor(from: "5.7.0"))
2022
],
2123
targets: [
2224
.target(
@@ -35,7 +37,7 @@ let package = Package(
3537
]),
3638
.testTarget(name: "ParseServerSwiftTests", dependencies: [
3739
.target(name: "ParseServerSwift"),
38-
.product(name: "XCTVapor", package: "vapor"),
40+
.product(name: "XCTVapor", package: "vapor")
3941
])
4042
]
4143
)

Sources/App/entrypoint.swift

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ParseServerSwift
1313
/// This extension is temporary and can be removed once Vapor gets this support.
1414
private extension Vapor.Application {
1515
static let baseExecutionQueue = DispatchQueue(label: "vapor.codes.entrypoint")
16-
16+
1717
func runFromAsyncMainEntrypoint() async throws {
1818
try await withCheckedThrowingContinuation { continuation in
1919
Vapor.Application.baseExecutionQueue.async { [self] in
@@ -33,11 +33,19 @@ enum Entrypoint {
3333
static func main() async throws {
3434
var env = try Environment.detect()
3535
try LoggingSystem.bootstrap(from: &env)
36-
36+
3737
let app = Application(env)
38-
defer { app.shutdown() }
39-
40-
try await configure(app)
38+
39+
defer {
40+
Task {
41+
// This may not delete all because it's async
42+
// Be sure to delete manually in dashboard
43+
await deleteHooks(app)
44+
}
45+
app.shutdown()
46+
}
47+
48+
try await parseServerSwiftConfigure(app)
4149
try await app.runFromAsyncMainEntrypoint()
4250
}
4351
}

Sources/ParseServerSwift/Extensions/Parse+Vapor.swift

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public extension ParseHookRequestable {
2323
In a single Parse Server environment, use options().
2424
*/
2525
func options(_ request: Request,
26+
// swiftlint:disable:next line_length
2627
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) throws -> API.Options {
2728
var options = self.options()
2829
options.insert(.serverURL(try serverURLString(request.url,
@@ -43,6 +44,7 @@ public extension ParseHookRequestable {
4344
*/
4445
func hydrateUser(options: API.Options = [],
4546
request: Request,
47+
// swiftlint:disable:next line_length
4648
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) async throws -> Self {
4749
var updatedOptions = try self.options(request, parseServerURLStrings: parseServerURLStrings)
4850
updatedOptions = updatedOptions.union(options)

Sources/ParseServerSwift/Models/HookFunction.swift

+25-17
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ extension HookFunction {
5050
.delete(options: [.serverURL(parseServerURLString)])
5151
default:
5252
throw ParseError(code: .otherCause,
53+
// swiftlint:disable:next line_length
5354
message: "Method \(method) is not supported for Hook Function: \"\(String(describing: hookFunction))\"")
5455
}
56+
// swiftlint:disable:next line_length
5557
configuration.logger.notice("Successful \(method); Hook Function: \"\(String(describing: hookFunction))\" on server: \(parseServerURLString)")
5658
} catch {
5759
if error.containedIn([.webhookError]) && method == .POST {
60+
// swiftlint:disable:next line_length
5861
configuration.logger.warning("Hook Function: \"\(String(describing: hookFunction))\"; warning: \(error); on server: \(parseServerURLString)")
5962
} else {
63+
// swiftlint:disable:next line_length
6064
configuration.logger.error("Could not \(method) Hook Function: \"\(String(describing: hookFunction))\"; error: \(error); on server: \(parseServerURLString)")
6165
}
6266
}
@@ -68,7 +72,7 @@ extension HookFunction {
6872

6973
// MARK: HookFunction - Fetch
7074
public extension HookFunction {
71-
75+
7276
/**
7377
Fetches a Parse Cloud Code hook function.
7478
- parameter path: A variadic list of paths.
@@ -80,8 +84,8 @@ public extension HookFunction {
8084
Will log an error for each `parseServerURLString` that returns an error.
8185
*/
8286
static func fetch(_ path: PathComponent...,
83-
name: String,
84-
parseServerURLStrings: [String]) async throws -> [String: HookFunction] {
87+
name: String,
88+
parseServerURLStrings: [String]) async throws -> [String: HookFunction] {
8589
try await fetch(path, name: name, parseServerURLStrings: parseServerURLStrings)
8690
}
8791

@@ -96,11 +100,11 @@ public extension HookFunction {
96100
Will log an error for each `parseServerURLString` that returns an error.
97101
*/
98102
static func fetch(_ path: [PathComponent],
99-
name: String,
100-
parseServerURLStrings: [String]) async throws -> [String: HookFunction] {
103+
name: String,
104+
parseServerURLStrings: [String]) async throws -> [String: HookFunction] {
101105
try await method(.PUT, path, name: name, parseServerURLStrings: parseServerURLStrings)
102106
}
103-
107+
104108
/**
105109
Fetches all Parse Cloud Code hook function.
106110
- parameter path: A variadic list of paths.
@@ -140,6 +144,7 @@ public extension HookFunction {
140144
hookFunctions[parseServerURLString] = try await hookFunction
141145
.fetchAll(options: [.serverURL(parseServerURLString)])
142146
} catch {
147+
// swiftlint:disable:next line_length
143148
configuration.logger.error("Could not fetchAll function: \"\(String(describing: hookFunction))\"; error: \(error); on server: \(parseServerURLString)")
144149
}
145150
}
@@ -149,7 +154,7 @@ public extension HookFunction {
149154

150155
// MARK: HookFunction - Create
151156
public extension HookFunction {
152-
157+
153158
/**
154159
Creates a Parse Cloud Code hook function.
155160
- parameter path: A variadic list of paths.
@@ -163,6 +168,7 @@ public extension HookFunction {
163168
*/
164169
static func create(_ path: PathComponent...,
165170
name: String,
171+
// swiftlint:disable:next line_length
166172
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) async throws -> [String: HookFunction] {
167173
try await create(path, name: name, parseServerURLStrings: parseServerURLStrings)
168174
}
@@ -180,14 +186,15 @@ public extension HookFunction {
180186
*/
181187
static func create(_ path: [PathComponent],
182188
name: String,
189+
// swiftlint:disable:next line_length
183190
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) async throws -> [String: HookFunction] {
184191
try await method(.POST, path, name: name, parseServerURLStrings: parseServerURLStrings)
185192
}
186193
}
187194

188195
// MARK: HookFunction - Update
189196
public extension HookFunction {
190-
197+
191198
/**
192199
Updates a Parse Cloud Code hook function.
193200
- parameter path: A variadic list of paths.
@@ -201,6 +208,7 @@ public extension HookFunction {
201208
*/
202209
static func update(_ path: PathComponent...,
203210
name: String,
211+
// swiftlint:disable:next line_length
204212
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) async throws -> [String: HookFunction] {
205213
try await update(path, name: name, parseServerURLStrings: parseServerURLStrings)
206214
}
@@ -218,14 +226,15 @@ public extension HookFunction {
218226
*/
219227
static func update(_ path: [PathComponent],
220228
name: String,
229+
// swiftlint:disable:next line_length
221230
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) async throws -> [String: HookFunction] {
222231
try await method(.PUT, path, name: name, parseServerURLStrings: parseServerURLStrings)
223232
}
224233
}
225234

226235
// MARK: HookFunction - Delete
227236
public extension HookFunction {
228-
237+
229238
/**
230239
Removes a Parse Cloud Code hook function.
231240
- parameter path: A variadic list of paths.
@@ -238,6 +247,7 @@ public extension HookFunction {
238247
*/
239248
static func delete(_ path: PathComponent...,
240249
name: String,
250+
// swiftlint:disable:next line_length
241251
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) async throws {
242252
try await delete(path, name: name, parseServerURLStrings: parseServerURLStrings)
243253
}
@@ -254,6 +264,7 @@ public extension HookFunction {
254264
*/
255265
static func delete(_ path: [PathComponent],
256266
name: String,
267+
// swiftlint:disable:next line_length
257268
parseServerURLStrings: [String] = ParseServerSwift.configuration.parseServerURLStrings) async throws {
258269
try await method(.DELETE, path, name: name, parseServerURLStrings: parseServerURLStrings)
259270
}
@@ -276,8 +287,7 @@ public extension RoutesBuilder {
276287
name: String,
277288
use closure: @escaping (Request) async throws -> Response
278289
) -> Route
279-
where Response: AsyncResponseEncodable
280-
{
290+
where Response: AsyncResponseEncodable {
281291
self.on(path,
282292
name: name,
283293
use: closure)
@@ -298,8 +308,7 @@ public extension RoutesBuilder {
298308
name: String,
299309
use closure: @escaping (Request) async throws -> Response
300310
) -> Route
301-
where Response: AsyncResponseEncodable
302-
{
311+
where Response: AsyncResponseEncodable {
303312
self.on(path,
304313
name: name,
305314
use: closure)
@@ -322,8 +331,7 @@ public extension RoutesBuilder {
322331
name: String,
323332
use closure: @escaping (Request) async throws -> Response
324333
) -> Route
325-
where Response: AsyncResponseEncodable
326-
{
334+
where Response: AsyncResponseEncodable {
327335
self.on(path,
328336
body: body,
329337
name: name,
@@ -347,13 +355,13 @@ public extension RoutesBuilder {
347355
name: String,
348356
use closure: @escaping (Request) async throws -> Response
349357
) -> Route
350-
where Response: AsyncResponseEncodable
351-
{
358+
where Response: AsyncResponseEncodable {
352359
Task {
353360
do {
354361
await configuration.hooks.updateFunctions(try await HookFunction.create(path,
355362
name: name))
356363
} catch {
364+
// swiftlint:disable:next line_length
357365
configuration.logger.error("Could not create HookFunction route for path: \(path); name: \(name) on servers: \(configuration.parseServerURLStrings) because of error: \(error)")
358366
}
359367
}

0 commit comments

Comments
 (0)