Skip to content

Conversation

@vdusek
Copy link
Contributor

@vdusek vdusek commented May 17, 2024

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:
# 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)   
# 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:
# 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)
# 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

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):
# 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):
# 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.

@github-actions github-actions bot added this to the 89th sprint - Tooling team milestone May 17, 2024
@github-actions github-actions bot added the t-tooling Issues with this label are in the ownership of the tooling team. label May 17, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Pull Request Tookit has failed!

Pull request is neither linked to an issue or epic nor labeled as adhoc!

@vdusek vdusek requested review from B4nan and jirimoravcik May 17, 2024 12:51
@vdusek vdusek merged commit 186afe7 into master May 20, 2024
@vdusek vdusek deleted the fix-task-run-abort branch May 20, 2024 11:23
# Changelog

## [1.6.5](../../releases/tag/v1.6.5) - Not released yet
## [1.7.0](../../releases/tag/v1.7.0) - Not released yet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a feature release when you only have fixes in it?

Copy link
Contributor Author

@vdusek vdusek May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From PR description:

In the async version it results in last_run method being async (should not be released as patch version).

So, since we are making additional requests, the last_run method must be made async. This change is technically breaking, although the original implementation was broken. Therefore, I have released it as a new minor version. This means it will not be updated automatically if you are using a tilde pin like apify-client~=1.6.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then please mention it in the changelog too. I would still go with a patch release personally, especially since it was broken before anyway, but it's not a huge deal. I don't know how common it is to lock versions via ~, but I am quite sure people do not do that to get around breaking changes.

jbartadev added a commit that referenced this pull request May 29, 2024
* master:
  chore: update dev deps (#227)
  chore: update dev deps and gh actions pipelines (#226)
  chore: Add Python Client examples [docs] (#191)
  Configure Renovate (#76)
  chore: bump version to 1.7.1 (#193)
  fix: aborting of last Actor/task run (#192)
  chore: Automatic docs theme update [skip ci]

# Conflicts:
#	website/sidebars.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants