blob: 023a2b75e6b45cf2e96bc56d54945e2ce0891326 [file]
#ifndef PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_SCHEDULER_INTERFACE_H_
#define PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_SCHEDULER_INTERFACE_H_
#include "absl/functional/any_invocable.h"
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
namespace safepower_agent {
class SchedulerInterface {
public:
virtual ~SchedulerInterface() = default;
// Schedule a task that will call a function every interval
// Returns an error if name is already in use.
// A running periodic task is allowed to reschedule itself under the same
// name (e.g., by calling DelayCall or PeriodicCall from within its callback),
// provided the rescheduling call is made synchronously from the same thread
// executing the callback.
virtual absl::Status PeriodicCall(absl::AnyInvocable<void()> fn,
absl::Duration interval,
absl::string_view name) = 0;
// Schedule task that will call a function once after waitDuration
// Returns an error if name is already in use.
// A running delayed task is allowed to reschedule itself under the same
// name (e.g., by calling DelayCall or PeriodicCall from within its callback),
// provided the rescheduling call is made synchronously from the same thread
// executing the callback.
virtual absl::Status DelayCall(absl::AnyInvocable<void() &&> fn,
absl::Duration wait_duration,
absl::string_view name) = 0;
// Cancel a Scheduled task permanently
// returns an error if name is not in use
virtual absl::Status CancelCall(absl::string_view name) = 0;
// Cancel all Scheduled task permanently
virtual absl::Status CancelAll() = 0;
// Explicitly disables the Scheduler
virtual absl::Status Shutdown() = 0;
};
} // namespace safepower_agent
#endif // PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_SCHEDULER_INTERFACE_H_