MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / handle_job_forget

Function handle_job_forget

crates/hyperqueue/src/server/client/mod.rs:792–826  ·  view source on GitHub ↗

Forgetting jobs can release a lot of memory and perform a lot of destructors. Since this happens in synchronous code, it can stall the event loop, which can lead to e.g. missing worker heartbeats and other problems. We thus return the forgotten jobs, so that we can drop them later in a separate thread.

(
    state_ref: &StateRef,
    senders: &Senders,
    selector: &IdSelector,
    allowed_statuses: Vec<Status>,
)

Source from the content-addressed store, hash-verified

790///
791/// We thus return the forgotten jobs, so that we can drop them later in a separate thread.
792fn handle_job_forget(
793 state_ref: &StateRef,
794 senders: &Senders,
795 selector: &IdSelector,
796 allowed_statuses: Vec<Status>,
797) -> (ToClientMessage, Vec<Job>) {
798 let mut state = state_ref.get_mut();
799 let job_ids: Vec<JobId> = get_job_ids(&state, selector);
800 let mut forgotten: usize = 0;
801
802 let mut forgotten_jobs = Vec::with_capacity(job_ids.len());
803 for &job_id in &job_ids {
804 let can_be_forgotten = state
805 .get_job(job_id)
806 .map(|j| {
807 j.is_terminated() && allowed_statuses.contains(&job_status(&j.make_job_info(false)))
808 })
809 .unwrap_or(false);
810 if can_be_forgotten {
811 if let Some(job) = state.forget_job(job_id) {
812 forgotten_jobs.push(job);
813 }
814 forgotten += 1;
815 }
816 }
817 state.try_release_memory();
818 senders.server_control.try_release_memory();
819
820 let ignored = job_ids.len() - forgotten;
821
822 (
823 ToClientMessage::ForgetJobResponse(ForgetJobResponse { forgotten, ignored }),
824 forgotten_jobs,
825 )
826}
827
828fn handle_get_list(state_ref: &StateRef, workers: bool) -> ToClientMessage {
829 let state = state_ref.get();

Callers 1

client_rpc_loopFunction · 0.85

Calls 12

get_job_idsFunction · 0.85
job_statusFunction · 0.85
ForgetJobResponseClass · 0.85
get_jobMethod · 0.80
containsMethod · 0.80
make_job_infoMethod · 0.80
pushMethod · 0.80
get_mutMethod · 0.45
lenMethod · 0.45
is_terminatedMethod · 0.45
forget_jobMethod · 0.45
try_release_memoryMethod · 0.45

Tested by

no test coverage detected