async def test_run_tasks_only_on_new_versions( db, user, package_version, dao, channel_name, package_name, supervisor ): func_serialized = pickle.dumps(dummy_func) job = Job(owner_id=user.id, manifest=func_serialized, items_spec="*") db.add(job) db.commit() supervisor.run_jobs() new_jobs = supervisor.run_tasks() db.refresh(job) task = db.query(Task).one() await new_jobs[0].wait() supervisor.check_status() db.refresh(task) db.refresh(job) assert task.status == TaskStatus.success assert job.status == JobStatus.success job.status = JobStatus.pending db.commit() supervisor.run_jobs() new_jobs = supervisor.run_tasks() supervisor.check_status() db.refresh(job) assert not new_jobs assert job.status == JobStatus.success filename = "test-package-0.2-0.tar.bz2" add_package_version(filename, "0.2", channel_name, user, dao, package_name) job.status = JobStatus.pending db.commit() supervisor.run_jobs() new_jobs = supervisor.run_tasks() assert len(new_jobs) == 1 assert job.status == JobStatus.running assert len(job.tasks) == 2 assert job.tasks[0].status == TaskStatus.success assert job.tasks[1].status == TaskStatus.pending # force rerunning job.status = JobStatus.pending supervisor.run_jobs(force=True) db.refresh(job) new_jobs = supervisor.run_tasks() assert len(job.tasks) == 4 assert len(new_jobs) == 2
def test_refresh_job(auth_client, user, db, package_version, supervisor): func_serialized = pickle.dumps(dummy_func) job = Job( owner_id=user.id, manifest=func_serialized, items_spec="*", status=JobStatus.success, ) task = Task(job=job, status=TaskStatus.success, package_version=package_version) db.add(job) db.add(task) db.commit() assert job.status == JobStatus.success assert len(job.tasks) == 1 response = auth_client.patch(f"/api/jobs/{job.id}", json={"status": "pending"}) assert response.status_code == 200 db.refresh(job) assert job.status == JobStatus.pending assert len(job.tasks) == 1 supervisor.run_jobs() supervisor.check_status() assert job.status == JobStatus.success assert len(job.tasks) == 1 response = auth_client.patch( f"/api/jobs/{job.id}", json={"status": "pending", "force": True} ) supervisor.run_jobs() db.refresh(job) assert job.status == JobStatus.running assert len(job.tasks) == 2 # forcing one job should not affect the other other_job = Job( id=2, owner_id=user.id, manifest=func_serialized, items_spec="*", status=JobStatus.success, ) job.status = JobStatus.pending db.add(other_job) db.commit() response = auth_client.patch( f"/api/jobs/{other_job.id}", json={"status": "pending", "force": True} ) db.refresh(job) assert job.status == JobStatus.pending assert len(job.tasks) == 2
def update_job( job_data: JobUpdateModel, db=Depends(get_db), job: job_db_models.Job = Depends(get_job_or_fail), auth: authorization.Rules = Depends(get_rules), ): """refresh job (re-run on new packages)""" auth.assert_jobs() job.status = job_data.status # type: ignore # ignore tasks that have already been run if job_data.force: run_jobs(db, job_id=job.id, force=True) db.commit()
def update_job( job_data: JobUpdateModel, db=Depends(get_db), job: job_db_models.Job = Depends(get_job_or_fail), auth: authorization.Rules = Depends(get_rules), ): """refresh job (re-run on new packages)""" auth.assert_jobs(owner_id=job.owner_id) job.status = job_data.status # type: ignore if job_data.force and job.status in [ JobStatus.running, JobStatus.pending, ]: # restart tasks that have already been run for task in job.tasks: task.status = "skipped" db.commit()