job_service

Job service that orchestrates job submission and management workflows.

Module Contents

job_service.process_job_submission(request, file) Tuple[django.http.JsonResponse | None, Dict[str, Any] | None]

Process a job submission from the web UI.

Extracts parameters from the Django request object (form fields + IP) and delegates to the shared process_job_submission_from_params function.

Parameters:
  • request – Django HTTP request (POST with multipart form data).

  • file – Uploaded CSV file extracted from request.FILES.

Returns:

Tuple of (error_response, success_data). On success: (None, {“message”: …, “public_id”: …}) On failure: (JsonResponse with error, None)

job_service.process_job_submission_from_params(params: Dict[str, Any], file, ip_address: str, *, quota_subject: str | None = None, daily_limit: int | None = None, user=None) Tuple[django.http.JsonResponse | None, Dict[str, Any] | None]

Core job-submission logic, decoupled from the HTTP request object.

This function is called by both the web-UI view (via process_job_submission) and the public API v1 submit endpoint. It accepts an explicit params dict and request IP so it can be used regardless of how the caller obtained those values.

Parameters:
  • params – Dict with keys: targets – e.g. [“kcat”], [“Km”, “kcat/Km”] methods – e.g. {“kcat”:”DLKcat”,”Km”:”UniKP”} handle_long_sequences– “truncate” or “skip” use_experimental – bool include_similarity_columns – bool canonicalize_substrates – bool disable_gpu_precompute – bool, internal benchmark toggle

  • file – A file-like object (Django InMemoryUploadedFile or io.BytesIO) containing the CSV data.

  • ip_address – Request source IP to store on the Job record.

  • quota_subject – Identifier used for rate-limit accounting (defaults to ip_address when omitted).

  • daily_limit – Optional explicit daily limit for quota_subject.

  • user – Optional ApiUser instance to attach to the created Job.

Returns:

Tuple of (error_response, success_data). On success: (None, {“message”: …, “public_id”: …}) On failure: (JsonResponse with error, None)

job_service.handle_quota_validation(quota_subject: str, requested_rows: int, *, daily_limit: int | None = None) django.http.JsonResponse | None

Handle quota validation and return error response if quota exceeded.

Parameters:
  • quota_subject – Quota subject identifier (IP or API-key subject).

  • requested_rows – Number of rows being requested

  • daily_limit – Optional explicit limit for this subject.

Returns:

JsonResponse with error if quota exceeded, None if allowed

job_service.create_job_record(params: Dict[str, Any], ip_address: str, requested_rows: int, user, *, quota_subject: str | None = None) api.models.Job

Create and save a new job record.

Parameters:
  • params – Job parameters dictionary

  • ip_address – Request source IP

  • requested_rows – Number of rows in the request

  • user – User model instance

  • quota_subject – Identifier used for quota accounting.

Returns:

Created Job instance

job_service.dispatch_prediction_task(public_id: str, params: Dict[str, Any], experimental_results: dict | None) None

Dispatch the appropriate Celery prediction task based on job parameters.

Uses one generic multi-target task that resolves each method at runtime.

Parameters:
  • public_id – Job public ID

  • params – Job parameters

  • experimental_results – Pre-fetched experimental results or None

job_service.dispatch_recon_xkg_cache_task(public_id: str, params: Dict[str, Any], experimental_results: dict | None) None

Dispatch ReconXKG cache preflight/assembly to the dedicated cache queue.

job_service.get_job_status_data(job: api.models.Job) Dict[str, Any]

Get formatted job status data.

Parameters:

job – Job model instance

Returns:

Dictionary containing job status information