Skip to content

Instantly share code, notes, and snippets.

@ricehornet
Last active January 7, 2021 22:13
Show Gist options
  • Save ricehornet/902be36075af16bdb5b7ce360544d7bf to your computer and use it in GitHub Desktop.
Save ricehornet/902be36075af16bdb5b7ce360544d7bf to your computer and use it in GitHub Desktop.
Generating ruralspark keycode
Generating ruralspark keycode
Angaza index is X*
# X/index is unit last message id
get_ruralspark_server_latest_token_data -> unit number exists on ruralspark server?
unit number exists on ruralspark server?
# do not have to worry about init case of last token index is 0 because this is handled in the units constructor
yes? -> ruralspark latest token index is equal to X?
no? -> Raise error require ticket to add unit on ruralspark side
ruralspark latest token index is equal to X?
# we DO NOT increment the index on our side unless we get a keycode back from ruralspark
yes? -> ruralspark_create_token_for_datetime
no? -> is ruralspark server index greater than Angaza index?
ruralspark_create_token_for_datetime
success -> return tokens and update Angaza index to newest token index
failure -> Angaza index is X
is ruralspark server index greater than Angaza index?
# implies that we did not commit a previous request or there were out of band tokens generated
yes? -> is ruralspark cutoff time equal to our desired cutoff within 1 week?
# implies that the ruralspark token is less than ours and this should never happen
no? -> fail as this implies some token data were lost by ruralspark
is ruralspark cutoff time equal to our desired cutoff within 1 week?
# return tokens that we previously generated but did not commit
yes? -> return tokens and update Angaza index to newest token index
# update ruralspark device credit state and return all tokens to bring device to that state
no? -> is ruralspark cutoff time ahead of desired cutoff time?
is ruralspark cutoff time ahead of desired cutoff time?
# implies that out-of-band tokens have alread pushed this unit past desired
yes? -> warn and do not return any new tokens
no? -> store all previously unshared tokens and request new token
store all previously unshared tokens and request new token
stored previously unshared tokens -> ruralspark_create_token_for_datetime
Raise error require ticket to add unit on ruralspark side
return tokens and update Angaza index to newest token index
request new tokens for new desired credit and then return all unshared tokens
fail as this implies some token data were lost by ruralspark
warn and do not return any new tokens
function render(model){
let current_state_name = model.active_states[0].name;
return $("h1",
{style: {color: "darkBlue"}},
`The current state is: ${current_state_name}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment