Commit 186afe7
authored
fix: aborting of last Actor/task run (#192)
## Problem description
### Aborting the last Actor run does not work
- Resulting in:
```
apify_client._errors.ApifyApiError: We have bad news: there is no API endpoint at this URL.
Did you specify it correctly?
```
- Code to reproduce it:
```python
# sync version
from apify_client import ApifyClient
TOKEN = '...'
ACTOR_ID = '...'
def actor_run_abort(apify_client: ApifyClient, actor_id: str) -> None:
actor_client = apify_client.actor(actor_id)
actor_client.call(wait_secs=1)
last_run = actor_client.last_run(status='RUNNING', origin='API')
aborted_info = last_run.abort()
print(f'aborted_info: {aborted_info}')
if __name__ == '__main__':
apify_client = ApifyClient(TOKEN)
actor_run_abort(apify_client, ACTOR_ID)
```
```python
# async version
import asyncio
from apify_client import ApifyClientAsync
TOKEN = '...'
ACTOR_ID = '...'
async def actor_run_abort_async(apify_client: ApifyClientAsync, actor_id: str) -> None:
actor_client = apify_client.actor(actor_id)
await actor_client.call(wait_secs=1)
last_run = await actor_client.last_run(status='RUNNING', origin='API')
aborted_info = await last_run.abort()
print(f'aborted_info: {aborted_info}')
if __name__ == '__main__':
apify_client = ApifyClientAsync(TOKEN)
asyncio.run(actor_run_abort_async(apify_client, ACTOR_ID))
```
### Aborting of the last task run does not work
- Resulting in:
```
apify_client._errors.ApifyApiError: We have bad news: there is no API endpoint at this URL.
Did you specify it correctly?
```
- Code to reproduce it:
```python
# sync version
from apify_client import ApifyClient
TOKEN = '...'
TASK_ID = '...'
def task_run_abort(apify_client: ApifyClient, task_id: str) -> None:
task_client = apify_client.task(task_id)
task_client.call(wait_secs=1)
last_run = task_client.last_run(status='RUNNING', origin='API')
aborted_info = last_run.abort()
print(f'aborted_info: {aborted_info}')
if __name__ == '__main__':
apify_client = ApifyClient(TOKEN)
task_run_abort(apify_client, TASK_ID)
```
```python
# async version
import asyncio
from apify_client import ApifyClientAsync
TOKEN = '...'
TASK_ID = '...'
async def task_run_abort_async(apify_client: ApifyClientAsync, task_id: str) -> None:
task_client = apify_client.task(task_id)
await task_client.call(wait_secs=1)
last_run = await task_client.last_run(status='RUNNING', origin='API')
aborted_info = await last_run.abort()
print(f'aborted_info: {aborted_info}')
if __name__ == '__main__':
apify_client = ApifyClientAsync(TOKEN)
asyncio.run(task_run_abort_async(apify_client, TASK_ID))
```
### Related issues
- The aborting of the last task run was reported in
#190. The aborting of
the last Actor run does not work as well as was described above.
### Solution
- Using additional API call to be able to call
`https://api.apify.com/v2/acts/{actorId}/runs/{runId}/abort` in both
cases.
- In the async version it results in `last_run` method being `async`
(should not be released as patch version).
- Copied from source code (Actor run):
```python
# Note:
# The API does not provide a direct endpoint for aborting the last Actor run using a URL like:
# https://api.apify.com/v2/acts/{actor_id}/runs/last/abort
# To achieve this, we need to implement a workaround using the following URL format:
# https://api.apify.com/v2/acts/{actorId}/runs/{runId}/abort
```
- Copied from source code (task run):
```python
# Note:
# The API does not provide a direct endpoint for aborting the last task run using a URL like:
# https://api.apify.com/v2/actor-tasks/{task_id}/runs/last/abort
# To achieve this, we need to implement a workaround using the following URL format:
# https://api.apify.com/v2/acts/{actorId}/runs/{runId}/abort
```
### Testing
- As we do not have a proper testing framework here, it was tested just
manually with the code examples provided at the beginning.1 parent 87b64bf commit 186afe7
File tree
4 files changed
+96
-9
lines changed- src/apify_client/clients/resource_clients
4 files changed
+96
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
348 | 354 | | |
349 | 355 | | |
350 | 356 | | |
| |||
355 | 361 | | |
356 | 362 | | |
357 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
358 | 379 | | |
359 | 380 | | |
360 | 381 | | |
| |||
634 | 655 | | |
635 | 656 | | |
636 | 657 | | |
637 | | - | |
| 658 | + | |
638 | 659 | | |
639 | 660 | | |
640 | 661 | | |
| |||
646 | 667 | | |
647 | 668 | | |
648 | 669 | | |
649 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
650 | 677 | | |
651 | 678 | | |
652 | 679 | | |
| |||
657 | 684 | | |
658 | 685 | | |
659 | 686 | | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
660 | 702 | | |
661 | 703 | | |
662 | 704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
270 | 276 | | |
271 | 277 | | |
272 | 278 | | |
| |||
277 | 283 | | |
278 | 284 | | |
279 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
280 | 301 | | |
281 | 302 | | |
282 | 303 | | |
| |||
491 | 512 | | |
492 | 513 | | |
493 | 514 | | |
494 | | - | |
| 515 | + | |
495 | 516 | | |
496 | 517 | | |
497 | 518 | | |
| |||
503 | 524 | | |
504 | 525 | | |
505 | 526 | | |
506 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
507 | 534 | | |
508 | 535 | | |
509 | 536 | | |
| |||
514 | 541 | | |
515 | 542 | | |
516 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
517 | 559 | | |
518 | 560 | | |
519 | 561 | | |
0 commit comments