Skip to content

Module dev_scheduler.erl

A simple scheduler scheme for AO.

Description

This device expects a message of the form: Process: #{ id, Scheduler: #{ Authority } }

   It exposes the following keys for scheduling:<code>#{ method: GET, path: <<"/info">> }</code> ->
           Returns information about the scheduler.<code>#{ method: GET, path: <<"/slot">> }</code> -> <code>slot(Msg1, Msg2, Opts)</code>
           Returns the current slot for a process.<code>#{ method: GET, path: <<"/schedule">> }</code> -> <code>get_schedule(Msg1, Msg2, Opts)</code>
           Returns the schedule for a process in a cursor-traversable format.<code>#{ method: POST, path: <<"/schedule">> }</code> -> <code>post_schedule(Msg1, Msg2, Opts)</code>
           Schedules a new message for a process, or starts a new scheduler
           for the given message.

Function Index

benchmark_suite/2*
benchmark_suite_test_/0*
cache_remote_schedule/2*Cache a schedule received from a remote scheduler.
check_lookahead_and_local_cache/4*Check if we have a result from a lookahead worker or from our local cache.
checkpoint/1Returns the current state of the scheduler.
do_get_remote_schedule/6*Get a schedule from a remote scheduler, unless we already have already read all of the assignments from the local cache.
do_post_schedule/4*Post schedule the message.
filter_json_assignments/4*Filter JSON assignment results from a remote legacy scheduler.
find_message_to_schedule/3*Search the given base and request message pair to find the message to schedule.
find_next_assignment/5*Get the assignments for a process from the message cache, local cache, or the inbox (thanks to a lookahead-worker).
find_process_message/4*Find the process message for a given process ID and base message.
find_remote_scheduler/3*Use the SchedulerLocation to find the remote path and return a redirect.
find_server/3*Locate the correct scheduling server for a given process.
find_server/4*
find_target_id/3*Find the schedule ID from a given request.
generate_local_schedule/5*Generate a GET /schedule response for a process.
generate_redirect/3*Generate a redirect message to a scheduler.
get_hint/2*If a hint is present in the string, return it.
get_local_assignments/4*Get the assignments for a process, and whether the request was truncated.
get_local_schedule_test/0*
get_location/3*Search for the location of the scheduler in the scheduler-location cache.
get_remote_schedule/5*Get a schedule from a remote scheduler, but first read all of the assignments from the local cache that we already know about.
get_schedule/3*Generate and return a schedule for a process, optionally between two slots -- labelled as from and to.
http_get_json_schedule_test_/0*
http_get_legacy_schedule_as_aos2_test_/0*
http_get_legacy_schedule_slot_range_test_/0*
http_get_legacy_schedule_test_/0*
http_get_legacy_slot_test_/0*
http_get_schedule/4*
http_get_schedule/5*
http_get_schedule_redirect/0*
http_get_schedule_redirect_test_/0*
http_get_schedule_test_/0*
http_get_slot/2*
http_init/0*
http_init/1*
http_post_legacy_schedule_test_/0*
http_post_schedule/0*
http_post_schedule_sign/4*
http_post_schedule_test_/0*
info/0This device uses a default_handler to route requests to the correct function.
is_local_scheduler/4*Determine if a scheduler is local.
location/3Router for record requests.
many_clients/1*
message_cached_assignments/2*Non-device exported helper to get the cached assignments held in a process.
next/3Load the schedule for a process into the cache, then return the next assignment.
node_from_redirect/2*Get the node URL from a redirect.
parse_schedulers/1General utility functions that are available to other modules.
post_legacy_schedule/4*
post_location/3*Generate a new scheduler location record and register it.
post_remote_schedule/4*
post_schedule/3*Schedules a new message on the SU.
read_local_assignments/4*Get the assignments for a process.
redirect_from_graphql/0*
redirect_from_graphql_test_/0*
redirect_to_hint_test/0*
register_location_on_boot_test/0*Test that a scheduler location is registered on boot.
register_new_process_test/0*
register_scheduler_test/0*
remote_slot/3*Get the current slot from a remote scheduler.
remote_slot/4*Get the current slot from a remote scheduler, based on the variant of the process's scheduler.
router/4The default handler for the scheduler device.
schedule/3A router for choosing between getting the existing schedule, or scheduling a new message.
schedule_message_and_get_slot_test/0*
single_resolution/1*
slot/3Returns information about the current slot for a process.
spawn_lookahead_worker/3*Spawn a new Erlang process to fetch the next assignments from the local cache, if we have them available.
start/0Helper to ensure that the environment is started.
status/3Returns information about the entire scheduler.
status_test/0*
test_process/0Generate a _transformed_ process message, not as they are generated by users.
test_process/1*
validate_next_slot/5*Validate the next slot generated by find_next_assignment.
without_hint/1*Take a process ID or target with a potential hint and return just the process ID.

Function Details

benchmark_suite/2 *

benchmark_suite(Port, Base) -> any()

benchmark_suite_test_/0 *

benchmark_suite_test_() -> any()

cache_remote_schedule/2 *

cache_remote_schedule(Schedule, Opts) -> any()

Cache a schedule received from a remote scheduler.

check_lookahead_and_local_cache/4 *

check_lookahead_and_local_cache(Msg1, ProcID, TargetSlot, Opts) -> any()

Check if we have a result from a lookahead worker or from our local cache. If we have a result in the local cache, we may also start a new lookahead worker to fetch the next assignments if we have them locally, ahead of time. This can be enabled/disabled with the scheduler_lookahead option.

checkpoint/1

checkpoint(State) -> any()

Returns the current state of the scheduler.

do_get_remote_schedule/6 *

do_get_remote_schedule(ProcID, LocalAssignments, From, To, Redirect, Opts) -> any()

Get a schedule from a remote scheduler, unless we already have already read all of the assignments from the local cache.

do_post_schedule/4 *

do_post_schedule(ProcID, PID, Msg2, Opts) -> any()

Post schedule the message. Msg2 by this point has been refined to only committed keys, and to only include the target message that is to be scheduled.

filter_json_assignments/4 *

filter_json_assignments(JSONRes, To, From, Opts) -> any()

Filter JSON assignment results from a remote legacy scheduler.

find_message_to_schedule/3 *

find_message_to_schedule(Msg1, Msg2, Opts) -> any()

Search the given base and request message pair to find the message to schedule. The precidence order for search is as follows: 1. A key in Msg2 with the value self, indicating that the entire message is the subject. 2. A key in Msg2 with another value, present in that message. 3. The body of the message. 4. The message itself.

find_next_assignment/5 *

find_next_assignment(Msg1, Msg2, Schedule, LastSlot, Opts) -> any()

Get the assignments for a process from the message cache, local cache, or the inbox (thanks to a lookahead-worker).

find_process_message/4 *

find_process_message(ProcID, Msg1, ToSched, Opts) -> any()

Find the process message for a given process ID and base message.

find_remote_scheduler/3 *

find_remote_scheduler(ProcID, Rest, Opts) -> any()

Use the SchedulerLocation to find the remote path and return a redirect. If there are multiple locations, try each one in turn until we find the first that matches.

find_server/3 *

find_server(ProcID, Msg1, Opts) -> any()

Locate the correct scheduling server for a given process.

find_server/4 *

find_server(ProcID, Msg1, ToSched, Opts) -> any()

find_target_id/3 *

find_target_id(Msg1, Msg2, Opts) -> any()

Find the schedule ID from a given request. The precidence order for search is as follows: [1. ToSched/id -- in the case of POST schedule, handled locally] 2. Msg2/target 3. Msg2/id when Msg2 has type: Process 4. Msg1/process/id 5. Msg1/id when Msg1 has type: Process 6. Msg2/id

generate_local_schedule/5 *

generate_local_schedule(Format, ProcID, From, To, Opts) -> any()

Generate a GET /schedule response for a process.

generate_redirect/3 *

generate_redirect(ProcID, SchedulerLocation, Opts) -> any()

Generate a redirect message to a scheduler.

get_hint/2 *

get_hint(Str, Opts) -> any()

If a hint is present in the string, return it. Else, return not_found.

get_local_assignments/4 *

get_local_assignments(ProcID, From, RequestedTo, Opts) -> any()

Get the assignments for a process, and whether the request was truncated.

get_local_schedule_test/0 *

get_local_schedule_test() -> any()

get_location/3 *

get_location(Msg1, Req, Opts) -> any()

Search for the location of the scheduler in the scheduler-location cache. If an address is provided, we search for the location of that specific scheduler. Otherwise, we return the location record for the current node's scheduler, if it has been established.

get_remote_schedule/5 *

get_remote_schedule(RawProcID, From, To, Redirect, Opts) -> any()

Get a schedule from a remote scheduler, but first read all of the assignments from the local cache that we already know about.

get_schedule/3 *

get_schedule(Msg1, Msg2, Opts) -> any()

Generate and return a schedule for a process, optionally between two slots -- labelled as from and to. If the schedule is not local, we redirect to the remote scheduler or proxy based on the node opts.

http_get_json_schedule_test_/0 *

http_get_json_schedule_test_() -> any()

http_get_legacy_schedule_as_aos2_test_/0 *

http_get_legacy_schedule_as_aos2_test_() -> any()

http_get_legacy_schedule_slot_range_test_/0 *

http_get_legacy_schedule_slot_range_test_() -> any()

http_get_legacy_schedule_test_/0 *

http_get_legacy_schedule_test_() -> any()

http_get_legacy_slot_test_/0 *

http_get_legacy_slot_test_() -> any()

http_get_schedule/4 *

http_get_schedule(N, PMsg, From, To) -> any()

http_get_schedule/5 *

http_get_schedule(N, PMsg, From, To, Format) -> any()

http_get_schedule_redirect/0 *

http_get_schedule_redirect() -> any()

http_get_schedule_redirect_test_/0 *

http_get_schedule_redirect_test_() -> any()

http_get_schedule_test_/0 *

http_get_schedule_test_() -> any()

http_get_slot/2 *

http_get_slot(N, PMsg) -> any()

http_init/0 *

http_init() -> any()

http_init/1 *

http_init(Opts) -> any()

http_post_legacy_schedule_test_/0 *

http_post_legacy_schedule_test_() -> any()

http_post_schedule/0 *

http_post_schedule() -> any()

http_post_schedule_sign/4 *

http_post_schedule_sign(Node, Msg, ProcessMsg, Wallet) -> any()

http_post_schedule_test_/0 *

http_post_schedule_test_() -> any()

info/0

info() -> any()

This device uses a default_handler to route requests to the correct function.

is_local_scheduler/4 *

is_local_scheduler(ProcID, ProcMsg, Rest, Opts) -> any()

Determine if a scheduler is local. If so, return the PID and options. We start the local server if we can be the scheduler and it does not already exist.

location/3

location(Msg1, Msg2, Opts) -> any()

Router for record requests. Expects either a POST or GET request.

many_clients/1 *

many_clients(Opts) -> any()

message_cached_assignments/2 *

message_cached_assignments(Msg, Opts) -> any()

Non-device exported helper to get the cached assignments held in a process.

next/3

next(Msg1, Msg2, Opts) -> any()

Load the schedule for a process into the cache, then return the next assignment. Assumes that Msg1 is a dev_process or similar message, having a Current-Slot key. It stores a local cache of the schedule in the priv/To-Process key.

node_from_redirect/2 *

node_from_redirect(Redirect, Opts) -> any()

Get the node URL from a redirect.

parse_schedulers/1

parse_schedulers(SchedLoc) -> any()

General utility functions that are available to other modules.

post_legacy_schedule/4 *

post_legacy_schedule(ProcID, OnlyCommitted, Node, Opts) -> any()

post_location/3 *

post_location(Msg1, RawReq, Opts) -> any()

Generate a new scheduler location record and register it. We both send the new scheduler-location to the given registry, and return it to the caller.

post_remote_schedule/4 *

post_remote_schedule(RawProcID, Redirect, OnlyCommitted, Opts) -> any()

post_schedule/3 *

post_schedule(Msg1, Msg2, Opts) -> any()

Schedules a new message on the SU. Searches Msg1 for the appropriate ID, then uses the wallet address of the scheduler to determine if the message is for this scheduler. If so, it schedules the message and returns the assignment.

read_local_assignments/4 *

read_local_assignments(ProcID, From, To, Opts) -> any()

Get the assignments for a process.

redirect_from_graphql/0 *

redirect_from_graphql() -> any()

redirect_from_graphql_test_/0 *

redirect_from_graphql_test_() -> any()

redirect_to_hint_test/0 *

redirect_to_hint_test() -> any()

register_location_on_boot_test/0 *

register_location_on_boot_test() -> any()

Test that a scheduler location is registered on boot.

register_new_process_test/0 *

register_new_process_test() -> any()

register_scheduler_test/0 *

register_scheduler_test() -> any()

remote_slot/3 *

remote_slot(ProcID, Redirect, Opts) -> any()

Get the current slot from a remote scheduler.

remote_slot/4 *

remote_slot(X1, ProcID, Node, Opts) -> any()

Get the current slot from a remote scheduler, based on the variant of the process's scheduler.

router/4

router(X1, Msg1, Msg2, Opts) -> any()

The default handler for the scheduler device.

schedule/3

schedule(Msg1, Msg2, Opts) -> any()

A router for choosing between getting the existing schedule, or scheduling a new message.

schedule_message_and_get_slot_test/0 *

schedule_message_and_get_slot_test() -> any()

single_resolution/1 *

single_resolution(Opts) -> any()

slot/3

slot(M1, M2, Opts) -> any()

Returns information about the current slot for a process.

spawn_lookahead_worker/3 *

spawn_lookahead_worker(ProcID, Slot, Opts) -> any()

Spawn a new Erlang process to fetch the next assignments from the local cache, if we have them available.

start/0

start() -> any()

Helper to ensure that the environment is started.

status/3

status(M1, M2, Opts) -> any()

Returns information about the entire scheduler.

status_test/0 *

status_test() -> any()

test_process/0

test_process() -> any()

Generate a transformed process message, not as they are generated by users. See dev_process for examples of AO process messages.

test_process/1 *

test_process(Address) -> any()

validate_next_slot/5 *

validate_next_slot(Msg1, Assignments, Lookahead, Last, Opts) -> any()

Validate the next slot generated by find_next_assignment.

without_hint/1 *

without_hint(Target) -> any()

Take a process ID or target with a potential hint and return just the process ID.