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

Custom usage counter example and integration test #611

Merged
merged 72 commits into from
Sep 24, 2021

Conversation

filipgolem
Copy link
Contributor

@filipgolem filipgolem commented Aug 30, 2021

A matching custom runtime:
https://github.com/golemfactory/ya-runtime-sdk/pull/16/files

presets.json:

{
  "ver": "V1",
  "active": [
    "wasm", "custom-counters", "vm"
  ],
  "presets": [
[...]
    {
      "name": "custom-counters",
      "exeunit-name": "custom-counters",
      "pricing-model": "linear",
      "initial-price": 0,
      "usage-coeffs": {
        "golem.usage.duration_sec": 0.0001,
        "golem.usage.cpu_sec": 0.0001,
        "golem.usage.custom.counter": 0.0003
      }
    }
  ]
}

@filipgolem filipgolem self-assigned this Aug 31, 2021
@filipgolem filipgolem changed the title Custom usage counter example Custom usage counter example and integration test Sep 6, 2021
Copy link
Contributor

@shadeofblue shadeofblue left a comment

Choose a reason for hiding this comment

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

added a few comments - plus, there should be some explanation (in the beginning of te source maybe? or in an accompanying README.md file) what the custom counter is and how it is increased so that the user can understand what's happening ... without some explanation, the whole example is very opaque...

plus, ideally, there should be a comment on how to run the example yourself, without goth

@filipgolem
Copy link
Contributor Author

debug_market_api=True,
debug_payment_api=True,
)
asyncio.run(main(args.running_time, args.subnet_tag, args.driver, args.network))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why we don't do if __name__ == '__main__' here?
Also, what with all this try/except, task.cancel() etc that we have in most examples?

I think this might be quite confusing for the reader who already knows & understands previous examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this necessary if we are not importing this file? It's just an example that is meant to be run directly, it even starts with #!/usr/bin/env python3. I wanted this example to be as simple as possible, handling NoPaymentAccountError and KeyboardInterrupt would make it more complicated. It's not great when most of the code in the example is boilerplate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Someone might want to import main from this example and use it in some other way. Why forbid them? It might make "playing with an example" easier.
I think this if __name__ ... is just a good standard, although I won't insist.

About NoPaymentAccountError/KeyboardInterrupt etc: I definitely agree this should be simplified, but I'd rather have the same in all examples (except hello world) and then fix it in all examples at the same time. But I won't insist here either : )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added if __name__ == "__main__": (9b238e6)

BTW: this example does not run indefinitely, so Ctrl+C wouldn't be typically pressed:

while datetime.now() < start_time + timedelta(seconds=self._running_time_sec):
...
parser.add_argument(
    "--running-time",
    default=30,

Copy link
Contributor

@shadeofblue shadeofblue left a comment

Choose a reason for hiding this comment

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

more or less looks good ...

added two more comments, it would be good @filipgolem if you could still include them

@filipgolem
Copy link
Contributor Author

more or less looks good ...

added two more comments, it would be good @filipgolem if you could still include them

Done.

@filipgolem filipgolem merged commit 4732395 into master Sep 24, 2021
@filipgolem filipgolem deleted the custom-usage-counter-example branch September 24, 2021 07:01
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.

3 participants