[pdm-devel] [PATCH proxmox-datacenter-manager v5 2/6] remote tasks: add background task for task polling, use new task cache
Dominik Csapak
d.csapak at proxmox.com
Thu Jul 3 13:25:40 CEST 2025
On 7/3/25 10:05, Lukas Wagner wrote:
[snip]
>>> + .collect())
>>> + }
>>> +}
>>> +
>>> +/// Get the timestamp from which on we should fetch tasks for a given remote.
>>> +/// The returned timestamp is a UNIX timestamp (in seconds).
>>> +fn get_cutoff_timestamp(remote: &Remote, state: &State) -> i64 {
>>> + let oldest_active = state.oldest_active_task.get(&remote.id).copied();
>>> + let youngest_archived = state.most_recent_archive_starttime.get(&remote.id).copied();
>>> +
>>> + match (oldest_active, youngest_archived) {
>>> + (None, None) => 0,
>>> + (None, Some(youngest_archived)) => youngest_archived,
>>> + (Some(oldest_active), None) => oldest_active,
>>> + (Some(oldest_active), Some(youngest_active)) => oldest_active.min(youngest_active),
>>> + }
>>> +}
>>> +
>>> +/// Rotate the task cache if necessary.
>>> +///
>>> +/// Returns Ok(true) the cache's files were rotated.
>>> +async fn rotate_cache(cache: TaskCache) -> Result<bool, Error> {
>>> + tokio::task::spawn_blocking(move || {
>>> + cache.rotate(
>>> + proxmox_time::epoch_i64(),
>>> + ROTATE_AFTER.as_secs(),
>>> + KEEP_OLD_FILES,
>>> + )
>>> + })
>>> + .await?
>>> +}
>>
>> in pbs, we start a worker task for the log rotation, maybe we want here too ?
>>
>
> Hmmm, do we have any guidelines when something should be a worker task and when not?
> I'm not opposed to it, but I'm just curious where to draw the line.
> Also, being a worker task also implies that it can be cancelled, right? Does that make sense for
> something like this?
>
no guidelines, but IMHO it makes sense if the task can take longer (e.g. when writing to disk)
and it's interesting for the user that it actually runs (and when).
also no, it does not make sense for it to be aborted really.
in any case, it might be enough here when we log into the syslog. creating a worker
can always be done later too
More information about the pdm-devel
mailing list