Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actor reboot method to the RunClient #140

Merged
merged 3 commits into from
Aug 22, 2023
Merged

Add actor reboot method to the RunClient #140

merged 3 commits into from
Aug 22, 2023

Conversation

vdusek
Copy link
Contributor

@vdusek vdusek commented Aug 4, 2023

Ticket

Description

  • I implement the reboot method in the same way as other methods calling endpoints (e.g. abort).

Test plan

I tried the following: Get the object of type RunClient using the last_run() method called on the specific Actor. And then call on it the reboot() method...

from src.apify_client import ApifyClient

# https://console.apify.com/account/integrations
API_TOKEN = 'todo'

# https://apify.com/vdusek/beautifulsoup-scraper
ACTOR_ID = 'apify/beautifulsoup-scraper'

apify_client = ApifyClient(API_TOKEN)
print(apify_client)

actor_client = apify_client.actor(ACTOR_ID)
print(actor_client)

last_run = actor_client.last_run()
print(last_run)

result = last_run.reboot()
print(result)

However, it does not work, and I got the unknown URL exception (full traceback below). The example of created URL: https://api.apify.com/v2/acts/apify~beautifulsoup-scraper/runs/last.

Could please guide me on how could I get the instance of RunClient from which I'll be able to call the reboot method? For example, I know I can access the runId like this last_run.get()['id'] but I have no idea how or where should I provide it. Thanks.

Full traceback:

Traceback (most recent call last):
  File "/home/vdusek/Apify/apify-client-python/run.py", line 19, in <module>
    result = last_run.reboot()
             ^^^^^^^^^^^^^^^^^
  File "/home/vdusek/Apify/apify-client-python/src/apify_client/_logging.py", line 68, in wrapper
    return fun(resource_client, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vdusek/Apify/apify-client-python/src/apify_client/clients/resource_clients/run.py", line 166, in reboot
    return self._reboot()
           ^^^^^^^^^^^^^^
  File "/home/vdusek/Apify/apify-client-python/src/apify_client/clients/base/actor_job_base_client.py", line 78, in _reboot
    response = self.http_client.call(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vdusek/Apify/apify-client-python/src/apify_client/_http_client.py", line 185, in call
    return _retry_with_exp_backoff(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vdusek/Apify/apify-client-python/src/apify_client/_utils.py", line 66, in _retry_with_exp_backoff
    raise e
  File "/home/vdusek/Apify/apify-client-python/src/apify_client/_utils.py", line 63, in _retry_with_exp_backoff
    return func(stop_retrying, attempt)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vdusek/Apify/apify-client-python/src/apify_client/_http_client.py", line 183, in _make_request
    raise ApifyApiError(response, attempt)
src.apify_client._errors.ApifyApiError: We have bad news: there is no API endpoint at this URL. Did you specify it correctly?

Edit: updated test script

from src.apify_client import ApifyClient

API_TOKEN = 'todo'
ACTOR_ID = 'apify/beautifulsoup-scraper'
apify_client = ApifyClient(API_TOKEN)
actor_client = apify_client.actor(ACTOR_ID)
last_run = actor_client.last_run()
run_id = last_run.get()['id']
result = apify_client.run(run_id).reboot()
print(result)

@vdusek vdusek marked this pull request as ready for review August 22, 2023 10:58
@jirimoravcik
Copy link
Member

I did:

from apify_client import ApifyClient

client = ApifyClient('todo')
actor_run_info = client .actor('apify/website-content-crawler').call(
        run_input={'startUrls': [{'url': 'https://docs.apify.com/platform'}]},
        wait_secs=1,
    )
client.run(actor_run_info['id']).reboot()

and it worked (screen from a different actor but you get the idea)
image

@vdusek
Copy link
Contributor Author

vdusek commented Aug 22, 2023

Thanks Jirko, I tested it as well, and it should be ready for a review.

vdusek and others added 2 commits August 22, 2023 14:00
Co-authored-by: Jiří Moravčík <jiri.moravcik@gmail.com>
@jirimoravcik jirimoravcik changed the title Add actor reboot method to the RunClient [WIP] Add actor reboot method to the RunClient Aug 22, 2023
Copy link
Member

@jirimoravcik jirimoravcik left a comment

Choose a reason for hiding this comment

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

Nice!

@vdusek vdusek merged commit dc9e56b into master Aug 22, 2023
15 checks passed
@vdusek vdusek deleted the add-actor-reboot branch August 22, 2023 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add actor reboot method to the RunClient
2 participants