You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/custom_ops/custom_targets.mdx
+12-7Lines changed: 12 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,13 +114,6 @@ This method should be implemented to:
114
114
- Update configuration when a target spec changes
115
115
- Clean up resources when a target is removed (`current` is `None`)
116
116
117
-
:::note Best practice: Keep all actions idempotent
118
-
119
-
Ideally this method should be idempotent, i.e. when calling this with the same arguments multiple times, the effect should remain the same.
120
-
For example, if the target is a directory, it should be a no-op if we try to create it (`previous` is `None`) when the directory already exists, and also a no-op if we try to delete it (`current` is `None`) when the directory does not exist.
121
-
122
-
:::
123
-
124
117
#### `describe(key) -> str` (Optional)
125
118
126
119
Returns a human-readable description of the target for logging and debugging purposes.
If not provided, the original spec will be passed directly to `mutate`.
167
160
161
+
## Best Practices
162
+
163
+
### Idempotency of Methods with Side Effects
164
+
165
+
`apply_setup_change()` and `mutate()` are the two methods that are expected to produce side effects.
166
+
We expect them to be idempotent, i.e. when calling them with the same arguments multiple times, the effect should remain the same.
167
+
168
+
For example,
169
+
- For `apply_setup_change()`, if the target is a directory, it should be a no-op if we try to create it (`previous` is `None`) when the directory already exists, and also a no-op if we try to delete it (`current` is `None`) when the directory does not exist.
170
+
- For `mutate()`, if a mutation is a deletion, it should be a no-op if the row does not exist.
171
+
172
+
This is to make sure when the system if left in an intermediate state, e.g. interrupted in the middle between a change is made and CocoIndex notes down the change is completed, the targets can still be gracefully rolled forward to the desired states after the system is resumed.
0 commit comments