Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Last active March 26, 2018 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JudeRosario/4da1a4460caf27024724c5250413c4b3 to your computer and use it in GitHub Desktop.
Save JudeRosario/4da1a4460caf27024724c5250413c4b3 to your computer and use it in GitHub Desktop.
Sample Sleep Task
<?php
class Staged_Sleep_Task extends Updraft_Task_1_0 {
public function initialise() {
$sleep_for = $this->get_random_time_intervals();
$this->update_option('sleep_for', $sleep_for);
}
public function run() {
$sleep_intervals = $this->get_option('sleep_for');
$this->log(sprintf("I will be sleeping for %s", implode(', ', $sleep_intervals)));
while(!empty($sleep_intervals)) {
$sleep = array_pop($sleep_intervals);
sleep($sleep);
$this->log("I slept for {$sleep}");
$this->update_option('sleep_for', $sleep_intervals);
}
return true;
}
public function get_random_time_intervals() {
$timers = array();
for($i = 0; $i<= 10; $i++){
$timers[] = rand(1,3);
}
return $timers;
}
public function get_default_options() {
return array();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment