Last active
March 26, 2018 14:08
-
-
Save JudeRosario/4da1a4460caf27024724c5250413c4b3 to your computer and use it in GitHub Desktop.
Sample Sleep Task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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