Skip to main content

BasePeriodicTaskManager

Git Source

Inherits: IPeriodicTaskManager, PolicyEnabler

State Variables

_periodicTaskAddresses

The periodic tasks

address[] internal _periodicTaskAddresses

_periodicTaskCustomSelectors

An optional custom selector for each periodic task

If the selector is set (non-zero), the task will be executed using the custom selector instead of the IPeriodicTask.execute function

mapping(address => bytes4) internal _periodicTaskCustomSelectors

Functions

_addPeriodicTask

function _addPeriodicTask(address task_, bytes4 customSelector_, uint256 index_) internal;

addPeriodicTask

Adds a periodic task to the end of the task list

This function reverts if:

  • The caller is not the admin
  • The task is already added
  • The task is not a valid periodic task
function addPeriodicTask(address task_) external override onlyAdminRole;

Parameters

NameTypeDescription
task_addressThe periodic task to add

addPeriodicTaskAtIndex

Adds a periodic task at a specific index in the task list

This function reverts if:

  • The caller is not the admin
  • The task is already added
  • The task is not a valid periodic task
  • The index is out of bounds If a custom selector is provided, care must be taken to ensure that the selector exists on {task_}. If the selector does not exist, all of the periodic tasks will revert.
function addPeriodicTaskAtIndex(address task_, bytes4 customSelector_, uint256 index_)
external
override
onlyAdminRole;

Parameters

NameTypeDescription
task_addressThe periodic task to add
customSelector_bytes4The custom selector to use for the task (or 0)
index_uint256The index where to insert the task

_removePeriodicTask

function _removePeriodicTask(uint256 index_) internal;

removePeriodicTask

Removes a periodic task from the task list

This function reverts if:

  • The caller is not the admin
  • The task is not added
function removePeriodicTask(address task_) external override onlyAdminRole;

Parameters

NameTypeDescription
task_addressThe periodic task to remove

removePeriodicTaskAtIndex

Removes a periodic task at a specific index

This function reverts if:

  • The caller is not the admin
  • The index is out of bounds
function removePeriodicTaskAtIndex(uint256 index_) external override onlyAdminRole;

Parameters

NameTypeDescription
index_uint256The index of the task to remove

_executePeriodicTasks

This function does not implement any logic to catch errors from the periodic tasks.

The logic is that if a periodic task fails, it should fail loudly and revert.

Any tasks that are non-essential can include a try-catch block to handle the error internally.

function _executePeriodicTasks() internal;

getPeriodicTaskCount

Gets the total number of periodic tasks

function getPeriodicTaskCount() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256_taskCount The number of periodic tasks

getPeriodicTaskAtIndex

Gets a periodic task at a specific index

function getPeriodicTaskAtIndex(uint256 index_) external view override returns (address, bytes4);

Parameters

NameTypeDescription
index_uint256The index of the task to get

Returns

NameTypeDescription
<none>address_task The address of the periodic task at the specified index
<none>bytes4_customSelector The custom selector for the task (or 0)

getPeriodicTasks

Gets all periodic tasks

function getPeriodicTasks() external view override returns (address[] memory, bytes4[] memory);

Returns

NameTypeDescription
<none>address[]_tasks An array of all periodic tasks in order
<none>bytes4[]_customSelectors An array of all custom selectors in order

getPeriodicTaskIndex

Gets the index of a specific periodic task

function getPeriodicTaskIndex(address task_) public view override returns (uint256 _index);

Parameters

NameTypeDescription
task_addressThe periodic task to find

Returns

NameTypeDescription
_indexuint256The index of the task, or type(uint256).max if not found

hasPeriodicTask

Checks if a periodic task exists in the manager

function hasPeriodicTask(address task_) public view override returns (bool);

Parameters

NameTypeDescription
task_addressThe periodic task to check

Returns

NameTypeDescription
<none>bool_exists True if the task exists, false otherwise