swh.scheduler.api.server module

swh.scheduler.api.server.get_global_scheduler()[source]
class swh.scheduler.api.server.SchedulerServerApp(*args, backend_class=None, backend_factory=None, **kwargs)[source]

Bases: swh.core.api.RPCServerApp

extra_type_decoders: Dict[str, Callable] = {'last_visit_status': <enum 'LastVisitStatus'>, 'scheduler_model': <function <lambda>>}

Value of extra_decoders passed to json_loads or msgpack_loads to be able to deserialize more object types.

extra_type_encoders: List[Tuple[type, str, Callable]] = [(<class 'swh.scheduler.model.BaseSchedulerModel'>, 'scheduler_model', <function _encode_model_object>), (<enum 'LastVisitStatus'>, 'last_visit_status', <function _encode_enum>)]

Value of extra_encoders passed to json_dumps or msgpack_dumps to be able to serialize more object types.

url_build_error_handlers: t.List[t.Callable[[Exception, str, dict], str]]

A list of functions that are called when url_for() raises a BuildError. Each function registered here is called with error, endpoint and values. If a function returns None or raises a BuildError the next function is tried.

New in version 0.9.

before_first_request_funcs: t.List[BeforeFirstRequestCallable]

A list of functions that will be called at the beginning of the first request to this instance. To register a function, use the before_first_request() decorator.

New in version 0.8.

teardown_appcontext_funcs: t.List[TeardownCallable]

A list of functions that are called when the application context is destroyed. Since the application context is also torn down if the request ends this is the place to store code that disconnects from databases.

New in version 0.9.

shell_context_processors: t.List[t.Callable[[], t.Dict[str, t.Any]]]

A list of shell context processor functions that should be run when a shell context is created.

New in version 0.11.

blueprints: t.Dict[str, 'Blueprint']

Maps registered blueprint names to blueprint objects. The dict retains the order the blueprints were registered in. Blueprints can be registered multiple times, this dict does not track how often they were attached.

New in version 0.7.

extensions: dict

a place where extensions can store application specific state. For example this is where an extension could store database engines and similar things.

The key must match the name of the extension module. For example in case of a “Flask-Foo” extension in flask_foo, the key would be 'foo'.

New in version 0.7.

view_functions: t.Dict[str, t.Callable]

A dictionary mapping endpoint names to view functions.

To register a view function, use the route() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

error_handler_spec: t.Dict[AppOrBlueprintKey, t.Dict[t.Optional[int], t.Dict[t.Type[Exception], 'ErrorHandlerCallable[Exception]']]]

A data structure of registered error handlers, in the format {scope: {code: {class: handler}}}`. The scope key is the name of a blueprint the handlers are active for, or None for all requests. The code key is the HTTP status code for HTTPException, or None for other exceptions. The innermost dictionary maps exception classes to handler functions.

To register an error handler, use the errorhandler() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

before_request_funcs: t.Dict[AppOrBlueprintKey, t.List[BeforeRequestCallable]]

A data structure of functions to call at the beginning of each request, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests.

To register a function, use the before_request() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

after_request_funcs: t.Dict[AppOrBlueprintKey, t.List[AfterRequestCallable]]

A data structure of functions to call at the end of each request, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests.

To register a function, use the after_request() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

teardown_request_funcs: t.Dict[AppOrBlueprintKey, t.List[TeardownCallable]]

A data structure of functions to call at the end of each request even if an exception is raised, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests.

To register a function, use the teardown_request() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

template_context_processors: t.Dict[AppOrBlueprintKey, t.List[TemplateContextProcessorCallable]]

A data structure of functions to call to pass extra context values when rendering templates, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests.

To register a function, use the context_processor() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

url_value_preprocessors: t.Dict[AppOrBlueprintKey, t.List[URLValuePreprocessorCallable]]

A data structure of functions to call to modify the keyword arguments passed to the view function, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests.

To register a function, use the url_value_preprocessor() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

url_default_functions: t.Dict[AppOrBlueprintKey, t.List[URLDefaultCallable]]

A data structure of functions to call to modify the keyword arguments when generating URLs, in the format {scope: [functions]}. The scope key is the name of a blueprint the functions are active for, or None for all requests.

To register a function, use the url_defaults() decorator.

This data structure is internal. It should not be modified directly and its format may change at any time.

swh.scheduler.api.server.argument_error_handler(exception)[source]
swh.scheduler.api.server.my_error_handler(exception)[source]
swh.scheduler.api.server.has_no_empty_params(rule)[source]
swh.scheduler.api.server.index()[source]
swh.scheduler.api.server.site_map()[source]
swh.scheduler.api.server.load_and_check_config(config_path, type='local')[source]
Check the minimal configuration is set to run the api or raise an

error explanation.

Parameters
  • config_path (str) – Path to the configuration file to load

  • type (str) – configuration type. For ‘local’ type, more checks are done.

Raises

Error if the setup is not as expected

Returns

configuration as a dict

swh.scheduler.api.server.make_app_from_configfile()[source]

Run the WSGI app from the webserver, loading the configuration from a configuration file.

SWH_CONFIG_FILENAME environment variable defines the configuration path to load.