Last active
March 5, 2022 17:48
-
-
Save tonyg/86420d0be8b2815c2de3b32e7996a9a7 to your computer and use it in GitHub Desktop.
syndicate-server supervised external service example -- see also https://git.syndicate-lang.org/syndicate-lang/syndicate-rs/src/commit/ec8ba36d6a7b0396c2b1bd083a4de20888e9b1ad/syndicate-server/protocols/schemas/externalServices.prs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from syndicate import relay, turn | |
from syndicate.during import During | |
import logging | |
@relay.service(name='inf', debug=True) | |
@During().add_handler | |
def main(args): | |
logging.info(f'in main {args}') | |
turn.on_stop(lambda: logging.info(f'args retracted {args}')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Demand that the server solve dependencies and then start the service: | |
<require-service <daemon sub-py>> | |
; Specify what it means to start the sub-py daemon: | |
<daemon sub-py { | |
; This is the command line | |
argv: ". ./.envrc >&2; /usr/bin/env python3 ./inf.py", | |
; This is the CWD for the subprocess | |
dir: "/home/tonyg/src/syndicate-py", | |
; This specifies that the program expects to speak BINARY syndicate protocol on stdio | |
protocol: application/syndicate, | |
}> | |
; As soon as the service starts, it publishes an object on well-known OID 0. | |
; The server advertises this fact as a `service-object` record. | |
; See https://git.syndicate-lang.org/syndicate-lang/syndicate-rs/src/commit/ec8ba36d6a7b0396c2b1bd083a4de20888e9b1ad/syndicate-server/src/services/daemon.rs#L345-L352 | |
; When the service-object appears, take the published object ref ($cap) and | |
; assert its config object to it - here, a dictionary with two entries, but can be anything | |
? <service-object <daemon sub-py> ?cap> [ | |
$cap { | |
config: $config, | |
log: $log, | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment