Skip to content

Commit

Permalink
refactor(job-db): set job status also in the main database (reanahub#423
Browse files Browse the repository at this point in the history
)

Up until now, reana-workflow-controller was updating the status of jobs
in the database. The updates are now managed by reana-job-controller
instead, as reana-workflow-controller should not be concerned by this.
  • Loading branch information
mdonadoni committed Jan 30, 2024
1 parent 212c537 commit 66d681f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion reana_job_controller/job_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
from reana_commons.utils import calculate_hash_of_dir, calculate_job_input_hash
from reana_db.database import Session
from reana_db.models import Job, JobCache
from reana_db.models import Job, JobCache, JobStatus

JOB_DB = {}

Expand Down Expand Up @@ -141,3 +141,9 @@ def update_job_status(job_id, status):
"""
logging.info(f"Updating status of job {job_id} to {status}")
JOB_DB[job_id]["status"] = status
try:
job_in_db = Session.query(Job).filter_by(id_=job_id).one()
job_in_db.status = JobStatus[status]
Session.commit()
except Exception as e:
logging.exception(f"Exception while updating status: {e}")
2 changes: 1 addition & 1 deletion reana_job_controller/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def create_job_in_db(self, backend_job_id):
job_db_entry = JobTable(
backend_job_id=backend_job_id,
workflow_uuid=self.workflow_uuid,
status=JobStatus.created.name,
status=JobStatus.created,
compute_backend=self.compute_backend,
cvmfs_mounts=self.cvmfs_mounts or "",
shared_file_system=self.shared_file_system or False,
Expand Down
4 changes: 4 additions & 0 deletions reana_job_controller/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ def create_job(): # noqa
job["backend_job_id"] = backend_jod_id
job["compute_backend"] = compute_backend
JOB_DB[str(job["job_id"])] = job
# FIXME: we do not detect whether the job has started running or not,
# so let's assume the job is running, even though it might be queued in
# the backend system
update_job_status(job_obj.job_id, JobStatus.running.name)
job_monitor_cls = current_app.config["JOB_MONITORS"][compute_backend]()
job_monitor_cls(
app=current_app._get_current_object(),
Expand Down

0 comments on commit 66d681f

Please sign in to comment.