Package: ferris-ef
STREAMZERO FX Executor HelperThis package can be used for logging and accessing service configuration, parameters, secrets and state through it's context.fromfx_efimportcontextAccessing package configurationfromfx_efimportcontextcontext.config.get('some_configuration_key')Accessing execution parametersfromfx_efimportcontextcontext.params.get('param_name')Accessing secretsWithfx_ef.context.secretsyou can access secrets stored on platform, project or package level.fromfx_efimportcontextcontext.secrets.get('secret_name')This command will first lookup for secret namedsecret_namewithin package secrets (defined insecrets.jsonfile of the package). If such key doesn't exist it will lookup for it within project secrets, and finally within platform's secrets. If secret with such name doesn't existNonewill be returned.Setting secretsUsingfx_ef.context.secrets.set(name, value, context)method you can set secrets on project and platform level.fromfx_efimportcontextcontext.secrets.set(name="platform_secret",value={"somekey":"someval"},context="platform")ParameterDescriptionnameName of the secret to be set. If secret with the same name already exist it will be updatedvalueValue of the secret that should be setcontextContext of the secret. Possible values areplatformandprojectAccessing package id and namefromfx_efimportcontextcontext.package.namecontext.package.idAccessing and updating package statefromfx_efimportcontextcontext.state.get()context.state.put("some_key","some_value")LoggingAvailable levels: DEBUG, INFO (default), ERROR, WARNING, CRITICALfromfx_efimportcontextcontext.logging.setLevel('INFO')context.logging.debug("debug msg")context.logging.info("info msg")context.logging.error("error msg")context.logging.warning("warning msg")context.logging.critical("critical msg")Sending eventsUsed for sending events to the system. Those events can be used to trigger another service execution.fromfx_efimportcontextprint("sending event with some data")context.events.send(event_type="sample_event_type",data={"some_key":"some_val"})ParameterDescriptionevent_typeType of the event (string)event_sourceSource of the event (if not provided it default to service name of current execution.dataEvent data (dict)topicName of the topic that event should be sent to. If not provider it will be set to system default.Scheduling retry of service executionUsed for scheduling next execution of the service from within that service script.fromfx_efimportcontextcontext.retry(minutes=0,hours=0,days=0,cron_expression=None,parameters={}):ParameterDescriptionminutesNumber of minutes until next executionhoursNumber of hours until next executiondaysNumber of days until next executioncron_expressionCron like expression when next execution should occur. It is not allowed to have/in the cron expression (e.g. */2 3 * * *) Ifcron_expressionis setminutes,hoursanddayswill be skippedparametersParameters that will be passed to next executionfromfx_efimportcontext# retry in 3 minutesjobid=context.scheduler.retry(minutes=3)# retry in 3 hoursjobid=context.scheduler.retry(hours=3)# retry in 3 daysjobid=context.scheduler.retry(days=3)# retry on 56th minute of next hourjobid=context.scheduler.retry(cron_expression="56 * * * *")Usingfx_effor local developmentTo usefx_effor local development and testing without need to run scripts through ExecutorEF_ENV=localenv variable must be set. When it is setfx_ef.contextwill be read from local fileef_env.jsonthat must be created within same directory as the script that is accessingfx_ef.context.ef_env.jsonmust have following structure:{"params":{"package_name":"some_package_name","package_id":"some_package_id","optional_param_1":"param_1_value","optional_param_2":"param_2_value"},"secrets":{"secret_param_1":"secret_1_value","secret_param_2":"secret_2_value"},"config":{"config_param_1":"config_1_value","config_param_2":"config_2_value"}}NOTE:params,package_nameandpackage_idare mandatory.WhenEF_ENV=localis set, package state is also stored and fetched from the local fileef_package_state.jsonwithin the same directory. If file does not exist it will be created on the fly.By defaultcontext.events.send(...)will be skipped when local env is set. If event should be sent anyway following should be added inconfigsection of theef_env.jsonfile:{"params":{...},"secrets":{...},"config":{"KAFKA_BOOTSTRAP_SERVER":"kafka","KAFKA_PORT":"9092","DEFAULT_TOPIC":"your_topic_name"}}ParameterDescriptionKAFKA_BOOTSTRAP_SERVERaddress of the kafka serverKAFKA_PORTkafka portDEFAULT_TOPICname of the default topic which will be used if it is not passed via send() method