|
2 | 2 |
|
3 | 3 |
|
4 | 4 | # TODO: Consider moving Regeneratable mixins to http/mixins if publishable and activatable are moved |
| 5 | +# TODO: Consider reorganizing functions in mixins to reduce duplication and differences amongst |
| 6 | +# different domains |
5 | 7 | class RegeneratableMixin[Model]: |
6 | 8 | """Regeneratable mixin adds the ability to regenerate resources.""" |
7 | 9 |
|
@@ -174,3 +176,167 @@ async def queue(self, resource_id: str, resource_data: ResourceData | None = Non |
174 | 176 | return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
175 | 177 | resource_id, "POST", "queue", json=resource_data |
176 | 178 | ) |
| 179 | + |
| 180 | + |
| 181 | +class IssuableMixin[Model]: |
| 182 | + """Issuable mixin adds the ability to issue resources.""" |
| 183 | + |
| 184 | + def issue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 185 | + """Issue resource. |
| 186 | +
|
| 187 | + Args: |
| 188 | + resource_id: Resource ID |
| 189 | + resource_data: Resource data will be updated |
| 190 | + """ |
| 191 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 192 | + resource_id, "POST", "issue", json=resource_data |
| 193 | + ) |
| 194 | + |
| 195 | + def cancel(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 196 | + """Cancel resource. |
| 197 | +
|
| 198 | + Args: |
| 199 | + resource_id: Resource ID |
| 200 | + resource_data: Resource data will be updated |
| 201 | + """ |
| 202 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 203 | + resource_id, "POST", "cancel", json=resource_data |
| 204 | + ) |
| 205 | + |
| 206 | + def error(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 207 | + """Error resource. |
| 208 | +
|
| 209 | + Args: |
| 210 | + resource_id: Resource ID |
| 211 | + resource_data: Resource data will be updated |
| 212 | + """ |
| 213 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 214 | + resource_id, "POST", "error", json=resource_data |
| 215 | + ) |
| 216 | + |
| 217 | + def pending(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 218 | + """Pending resource. |
| 219 | +
|
| 220 | + Args: |
| 221 | + resource_id: Resource ID |
| 222 | + resource_data: Resource data will be updated |
| 223 | + """ |
| 224 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 225 | + resource_id, "POST", "pending", json=resource_data |
| 226 | + ) |
| 227 | + |
| 228 | + def queue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 229 | + """Queue resource. |
| 230 | +
|
| 231 | + Args: |
| 232 | + resource_id: Resource ID |
| 233 | + resource_data: Resource data will be updated |
| 234 | + """ |
| 235 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 236 | + resource_id, "POST", "queue", json=resource_data |
| 237 | + ) |
| 238 | + |
| 239 | + def retry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 240 | + """Retry resource. |
| 241 | +
|
| 242 | + Args: |
| 243 | + resource_id: Resource ID |
| 244 | + resource_data: Resource data will be updated |
| 245 | + """ |
| 246 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 247 | + resource_id, "POST", "retry", json=resource_data |
| 248 | + ) |
| 249 | + |
| 250 | + def recalculate(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 251 | + """Recalculate resource. |
| 252 | +
|
| 253 | + Args: |
| 254 | + resource_id: Resource ID |
| 255 | + resource_data: Resource data will be updated |
| 256 | + """ |
| 257 | + return self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 258 | + resource_id, "POST", "recalculate", json=resource_data |
| 259 | + ) |
| 260 | + |
| 261 | + |
| 262 | +class AsyncIssuableMixin[Model]: |
| 263 | + """Issuable mixin adds the ability to issue resources.""" |
| 264 | + |
| 265 | + async def issue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 266 | + """Issue resource. |
| 267 | +
|
| 268 | + Args: |
| 269 | + resource_id: Resource ID |
| 270 | + resource_data: Resource data will be updated |
| 271 | + """ |
| 272 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 273 | + resource_id, "POST", "issue", json=resource_data |
| 274 | + ) |
| 275 | + |
| 276 | + async def cancel(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 277 | + """Cancel resource. |
| 278 | +
|
| 279 | + Args: |
| 280 | + resource_id: Resource ID |
| 281 | + resource_data: Resource data will be updated |
| 282 | + """ |
| 283 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 284 | + resource_id, "POST", "cancel", json=resource_data |
| 285 | + ) |
| 286 | + |
| 287 | + async def error(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 288 | + """Error resource. |
| 289 | +
|
| 290 | + Args: |
| 291 | + resource_id: Resource ID |
| 292 | + resource_data: Resource data will be updated |
| 293 | + """ |
| 294 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 295 | + resource_id, "POST", "error", json=resource_data |
| 296 | + ) |
| 297 | + |
| 298 | + async def pending(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 299 | + """Pending resource. |
| 300 | +
|
| 301 | + Args: |
| 302 | + resource_id: Resource ID |
| 303 | + resource_data: Resource data will be updated |
| 304 | + """ |
| 305 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 306 | + resource_id, "POST", "pending", json=resource_data |
| 307 | + ) |
| 308 | + |
| 309 | + async def queue(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 310 | + """Queue resource. |
| 311 | +
|
| 312 | + Args: |
| 313 | + resource_id: Resource ID |
| 314 | + resource_data: Resource data will be updated |
| 315 | + """ |
| 316 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 317 | + resource_id, "POST", "queue", json=resource_data |
| 318 | + ) |
| 319 | + |
| 320 | + async def retry(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: |
| 321 | + """Retry resource. |
| 322 | +
|
| 323 | + Args: |
| 324 | + resource_id: Resource ID |
| 325 | + resource_data: Resource data will be updated |
| 326 | + """ |
| 327 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 328 | + resource_id, "POST", "retry", json=resource_data |
| 329 | + ) |
| 330 | + |
| 331 | + async def recalculate( |
| 332 | + self, resource_id: str, resource_data: ResourceData | None = None |
| 333 | + ) -> Model: |
| 334 | + """Recalculate resource. |
| 335 | +
|
| 336 | + Args: |
| 337 | + resource_id: Resource ID |
| 338 | + resource_data: Resource data will be updated |
| 339 | + """ |
| 340 | + return await self._resource_action( # type: ignore[attr-defined, no-any-return] |
| 341 | + resource_id, "POST", "recalculate", json=resource_data |
| 342 | + ) |
0 commit comments