Skip to content
Snippets Groups Projects
Commit 928376f2 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

create user session before any user interaction

parent 65a00aab
No related branches found
No related tags found
1 merge request!10Resolve "Multiple analysis upload: not working for the first time"
Pipeline #117510 failed
...@@ -28,6 +28,15 @@ def csrf(request): ...@@ -28,6 +28,15 @@ def csrf(request):
return JsonResponse({"token": token}) return JsonResponse({"token": token})
@router.get("init-session")
def init_session(request):
if not request.session.session_key:
request.session.create()
request.session.set_expiry(60000)
return JsonResponse({"session": "ok"})
@router.post("add", response=AnalysisOutSchema) @router.post("add", response=AnalysisOutSchema)
def add( def add(
request, request,
...@@ -42,14 +51,17 @@ def add( ...@@ -42,14 +51,17 @@ def add(
if request.session.session_key: if request.session.session_key:
session_key = request.session.session_key session_key = request.session.session_key
else: else:
print("should not create a token !!!!!")
request.session.create() request.session.create()
request.session.set_expiry(60000) request.session.set_expiry(60000)
session_key = request.session.session_key session_key = request.session.session_key
print(session_key)
session = Session.objects.get(session_key=session_key) session = Session.objects.get(session_key=session_key)
aw = AnalysisWorkflow.objects.get(pk=1) aw = AnalysisWorkflow.objects.get(pk=1)
input_files = [ input_files = [
genome_path, genome_path,
] ]
params = {} params = {}
analysis = aw.invoke(session, input_files, params, f"{genomefile.name}") analysis = aw.invoke(session, input_files, params, f"{genomefile.name}")
...@@ -57,6 +69,7 @@ def add( ...@@ -57,6 +69,7 @@ def add(
return analysis return analysis
@router.get("/", response=list[AnalysisOutSchema]) @router.get("/", response=list[AnalysisOutSchema])
def list(request): def list(request):
session_key = request.session.session_key session_key = request.session.session_key
......
...@@ -65,6 +65,8 @@ class AnalysisWorkflow(Workflow): ...@@ -65,6 +65,8 @@ class AnalysisWorkflow(Workflow):
galaxy_inv = self.galaxy_workflow.invoke( galaxy_inv = self.galaxy_workflow.invoke(
datamap, history=history.galaxy_history, params=params datamap, history=history.galaxy_history, params=params
) )
try:
analysis = Analysis( analysis = Analysis(
name=history_name, name=history_name,
galaxy_id=galaxy_inv.id, galaxy_id=galaxy_inv.id,
...@@ -77,10 +79,14 @@ class AnalysisWorkflow(Workflow): ...@@ -77,10 +79,14 @@ class AnalysisWorkflow(Workflow):
datamap=datamap, datamap=datamap,
create_time=load_galaxy_invocation_time_to_datetime(galaxy_inv), create_time=load_galaxy_invocation_time_to_datetime(galaxy_inv),
) )
except ZeroDivisionError as e:
print(e)
finally:
analysis.save() analysis.save()
analysis.create_output_files() analysis.create_output_files(max_retry=20)
return analysis return analysis
def prepare_invocation( def prepare_invocation(
self, self,
session, session,
......
...@@ -6,12 +6,16 @@ export interface Props { ...@@ -6,12 +6,16 @@ export interface Props {
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
fluid: true fluid: true
}); });
useCsrfToken() const { csrfToken } = await useCsrfToken()
// init session
if (csrfToken.value) {
const { data, pending, error } = useFetch("/api/analysis/init-session", {
headers: [["X-CSRFToken", csrfToken.value]]
})
}
const scrollThreshold = ref(200) const scrollThreshold = ref(200)
const density = ref<'compact' | 'prominent'>("prominent") const density = ref<'compact' | 'prominent'>("prominent")
// Hanle CSRF token
function onScroll() { function onScroll() {
if (window.scrollY > scrollThreshold.value) { if (window.scrollY > scrollThreshold.value) {
density.value = "compact" density.value = "compact"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment