Skip to content

Commit fbd814b

Browse files
authored
fix: Existing Hooks are replaced with new ones on restart (#33)
* fix: Hooks should attempt to update if already exists * switch method to PUT * delete and put when already exists * delete then post
1 parent 7276ce7 commit fbd814b

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Sources/App/entrypoint.swift

-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ enum Entrypoint {
3737
let app = Application(env)
3838

3939
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-
}
4540
app.shutdown()
4641
}
4742

Sources/ParseServerSwift/Models/HookFunction.swift

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ extension HookFunction {
5959
if error.containedIn([.webhookError]) && method == .POST {
6060
// swiftlint:disable:next line_length
6161
configuration.logger.warning("Hook Function: \"\(String(describing: hookFunction))\"; warning: \(error); on server: \(parseServerURLString)")
62+
try await Self.method(.DELETE,
63+
path,
64+
name: name,
65+
parseServerURLStrings: parseServerURLStrings)
66+
return try await Self.method(method,
67+
path,
68+
name: name,
69+
parseServerURLStrings: parseServerURLStrings)
6270
} else {
6371
// swiftlint:disable:next line_length
6472
configuration.logger.error("Could not \(method) Hook Function: \"\(String(describing: hookFunction))\"; error: \(error); on server: \(parseServerURLString)")

Sources/ParseServerSwift/Models/HookTrigger.swift

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ extension HookTrigger {
6969
if error.containedIn([.webhookError]) && method == .POST {
7070
// swiftlint:disable:next line_length
7171
configuration.logger.warning("Hook Trigger: \"\(String(describing: hookTrigger))\"; warning: \(error); on server: \(parseServerURLString)")
72+
try await Self.method(.DELETE,
73+
path,
74+
className: className,
75+
triggerName: triggerName,
76+
parseServerURLStrings: parseServerURLStrings)
77+
return try await Self.method(method,
78+
path,
79+
className: className,
80+
triggerName: triggerName,
81+
parseServerURLStrings: parseServerURLStrings)
7282
} else {
7383
// swiftlint:disable:next line_length
7484
configuration.logger.error("Could not \(method) Hook Trigger: \"\(String(describing: hookTrigger))\"; error: \(error); on server: \(parseServerURLString)")

0 commit comments

Comments
 (0)