Skip to content

Commit

Permalink
Make fields configurable and move delete to end of updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Oct 23, 2023
1 parent e96ef70 commit e205576
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion samples/ServalApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ streamlit run serval_app.py
```

### Regenerating the Python Client
When the Serval API is updated, use the tool [swagger-to](https://pypi.org/project/swagger-to/) to generate a new `serval_client_module.py` using the following command:
When the Serval API is updated, download the "swagger.json" from the swagger endpoint and use the tool [swagger-to](https://pypi.org/project/swagger-to/) to generate a new `serval_client_module.py` using the following command in this directory:
```
swagger_to_py_client.py --swagger_path path/to/swagger.json --outpath serval_client_module.py
```
Expand Down
12 changes: 6 additions & 6 deletions samples/ServalApp/serval_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ def send_emails():
try:
def started(build:Build, email_server:ServalAppEmailServer, data=None):
print(f"\tStarted {build}")
session.delete(build)
email_server.send_build_started_email(build.email)
session.delete(build)
session.add(Build(build_id=build.build_id, engine_id=build.engine_id, email=build.email, state=State.Active, corpus_id=build.corpus_id))

def faulted(build:Build, email_server:ServalAppEmailServer, data=None):
print(f"\tFaulted {build}")
session.delete(build)
email_server.send_build_faulted_email(build.email, error=data)
session.delete(build)

def completed(build:Build, email_server:ServalAppEmailServer, data=None):
print(f"\tCompleted {build}")
session.delete(build)
pretranslations = client.translation_engines_get_all_pretranslations(build.engine_id, build.corpus_id)
email_server.send_build_completed_email(build.email, '\n'.join([f"{'|'.join(pretranslation.refs)}\t{pretranslation.translation}" for pretranslation in pretranslations]))
session.delete(build)

def update(build:Build, email_server:ServalAppEmailServer, data=None):
print(f"\tUpdated {build}")

serval_auth = ServalBearerAuth()
client = RemoteCaller(url_prefix="https://prod.serval-api.org",auth=serval_auth)
client = RemoteCaller(url_prefix=os.environ.get('SERVAL_HOST_URL'),auth=serval_auth)
responses:"dict[str,function]" = {"Completed":completed, "Faulted":faulted, "Canceled":faulted}

def get_update(build:Build, email_server:ServalAppEmailServer):
Expand All @@ -63,7 +63,7 @@ def send_updates(email_server:ServalAppEmailServer):
with ServalAppEmailServer(os.environ.get('SERVAL_APP_EMAIL_PASSWORD')) as email_server:
while(True):
send_updates(email_server)
sleep(300) #Once every five minutes...
sleep(os.environ.get('SERVAL_APP_UPDATE_FREQ_SEC',300))
except Exception as e:
print(e)
st.session_state['background_process_has_started'] = False
Expand Down Expand Up @@ -110,7 +110,7 @@ def submit():
)
)
)
build = json.loads(client.translation_engines_start_build(engine['id'], TranslationBuildConfig(pretranslate=[PretranslateCorpusConfig(corpus_id=corpus["id"], text_ids= [] if st.session_state['source_files'][0].name[-4:] == '.zip' else list(map(lambda f: f.name, st.session_state['source_files'])))], options="{\"max_steps\":10}")))
build = json.loads(client.translation_engines_start_build(engine['id'], TranslationBuildConfig(pretranslate=[PretranslateCorpusConfig(corpus_id=corpus["id"], text_ids= [] if st.session_state['source_files'][0].name[-4:] == '.zip' else list(map(lambda f: f.name, st.session_state['source_files'])))], options="{\"max_steps\":" + os.environ.get('SERVAL_APP_MAX_STEPS',10) + "}")))
session.add(Build(build_id=build['id'],engine_id=engine['id'],email=st.session_state['email'],state=build['state'],corpus_id=corpus['id']))
session.commit()

Expand Down

0 comments on commit e205576

Please sign in to comment.