# User Scheduled Tasks ## Dec 7, 2022 ## Attendees: dkliban, dalley, x9c4, bmbouter ## Notes * Task locking is hard to do from the schedule. * Scheduling any Python method is unsafe. * Maybe we can do only "scheduled sync" as a feature. If we think about scheduled sync: * We should make the tasks self aware. * Remotes should be able to represent _all_ sync options. We have a viewset: https://github.com/pulp/pulpcore/blob/main/pulpcore/app/viewsets/task.py#L238 Try to model after systemd timer management? e.g. `systemctl list-timers` Use cases: - Scheduled Sync - Scheduled Orphan Cleanup - Scheduled Task Cleanup - Scheduled Uploads Cleanup ## Brainstorm self aware tasks - Create a `@pulp_task` decorator that adds a `dispatch` method to the task function. - `general_create.dispatch(kwargs={"name": "test"}, task_group=tg) # close to current state` - `general_create.dispatch(name="test") # ignore task_groups` - `general_create.dispatch(serializer=ser) # all tasks just handle a serializer` - How can tasks identify their locked resources? - Ask the passed serializer. - add `@pulp_task_arg` decorator to specify what parameter leads to exclusive/shared resources, how it is serialized, ... - When we tie tasks to serializers, we could return the serializers output as the task result. - Observation: A task is usually a result of a rest call to drf. So there is a serializer and a verb involved. This should be sufficient to define how a task is meant to be run (including reserved_resources). - And sometimes an instance of some kind. - Writing tasks should be as easy as writing views.