Giter Club home page Giter Club logo

yapapi-service-manager's Introduction

yapapi-service-manager

Helper tool for management of Golem-based services.

Installation:

$ pip3 install git+https://github.com/golemfactory/yapapi-service-manager.git

yapapi-service-manager vs yapapi

The official Golem requestor agent library for Python is yapapi. yayapi is used internally in yapapi-service-manager, so there's exactly nothing this library can do that is not available in pure yapapi.

yapapi-service-manager provides a higher-level services API than yapapi. Main features:

  • create/destroy services on demand
  • service wrapper objects that are created before agreement is signed & stay after it was terminated
  • fire-and-forget methods with synchronous interface (although this is still an async library that will not work when called in non-async context)

There are a lot of features available in yapapi but not in yapapi-service-manager. If you need either one of:

  • task API
  • efficient way of spawning multiple services in clusters
  • stable backward-compatible API & support

then, you should use pure yapapi.

Note: This library changes the way services are managed, but the way they are defined is exactly the same as in yapapi.

More generally, this library should be considered a temporary stage in requestor API development. In the long term, yapapi-service-manager will either be merged into yapapi (with possible serious API changes) or abandoned.

Examples

  1. Simple service that just prints provider time few times. This is pretty useless, just demonstrates the base usage.
$ python3 examples/clock.py
  1. "Standard" interactive python console, but running on a provider machine.
$ python3 examples/python_shell.py
  1. More complex usage: Erigon. Features:
  • custom runtime
  • integration with Quart http server

Detailed description of this example is in the Golem handbook.

Quickstart

from yapapi_service_manager import ServiceManager

#   Initialize the ServiceManager. You should never have more than one active ServiceManager.
service_manager = ServiceManager(
    # Dictionary with yapapi.Golem config (https://handbook.golem.network/yapapi/api-reference#_engine-objects)
    executor_cfg,  
    
    # Handler function executed when yapapi.Executor raises an exception
    # Default handler just stops the current event loop
    golem_exception_handler=yapapi_service_manager.stop_on_golem_exception,
    
    log_file='log.log',
)

#   Request service creation. From the yapapi POV, this is equivalent to
#   https://handbook.golem.network/yapapi/api-reference#run_service (with num_instances = 1)
service_wrapper = service_manager.create_service(
    # Service implementation, class inheriting from yapapi.services.Service
    service_cls,

    # Factory function returning instance of yapapi_service_manager.ServiceWrapper
    # Sample usage --> Erigon example
    service_wrapper_factory=yapapi_service_manager.ServiceWrapper,
    
    # Optional dictionary of parameters passed directly to Golem.run_service
    # (e.g. network or instance_params). IMPORTANT NOTE: some params might influence the number
    # of instances created. This must be avoided, exactly one instance should be always created.
    run_service_params=None,
)

service_wrapper.stop()   # Stop the service. This terminates the agreement.
service_wrapper.status   # pending -> starting -> running -> stopping -> stopped
                         # (also possible-but-not-expected: unresponsive and failed)
service_wrapper.service  # Instance of service_cls

await service_manager.create_network(ip, **kwargs)  # redirects to `yapapi.Golem.create_network`

await service_manager.close()  # Close the Executor, stop all Golem-related work

Known issues

There are no known issues except for mentioned here.

yapapi-service-manager's People

Contributors

johny-b avatar wiezzel avatar pnowosie avatar

Stargazers

Kevin Alexander Scott Jellis avatar

Watchers

 avatar Viggith avatar Piotr Chromiec avatar  avatar  avatar

yapapi-service-manager's Issues

traceback in get_payload fails silently

E.g. in the clock example, add 1/0 in get_payload and there are no errors, just no demand is published to the market & everything hangs forever. In pure yapapi this stops the script.

update `yapapi` requirement

This should be done when yapapi 0.7 is released.
yapapi-service-manager should require a released yapapi, not b0.7 branch.

Enable logging configuration

Currently there is

enable_default_logger(log_file=log_file)

in ServiceManager.__init__. This is a good default, but there should be an option to turn this off.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.