There is a common pattern emerging in the way we run offchain workers. Usually we want them to be triggered:
After a block number set in the storage
Only once after that threshold,
But retry after the previous run does not seem to complete.
Randomly for different validators, etc
That could be easily made into a re-usable piece of code that would schedule the runs. Rough (and incomplete) proposal from @kianenigma
fn offchain_worker() {
// simplest case. It basically adds a `should_run` impl that always return true
let OffchainLimit::default()::build();
// Run every N block
let OffchainLimit::default()::with_interval(10)
// We can also implement maybe your idea of
let OffchainLimit::default().with_interval(10).randomise(2)
/// after some point in time
let OffchainLimit::after(Storage::get(()).with_interval(10).randomise(2)
// Any more attributes. I really think the idea of _composability_ can be very neat here, which
// the builder pattern does very well.
Offchain workshop follow up task.
There is a common pattern emerging in the way we run offchain workers. Usually we want them to be triggered:
That could be easily made into a re-usable piece of code that would schedule the runs. Rough (and incomplete) proposal from @kianenigma