AllaerdScheduler

The Woocommerce CSV Import Allaerd Scheduler class.

Defined (1)

The class is defined in the following location(s).

/import/classes/Scheduler.php  
  1. class Scheduler extends AsyncRequest 
  2. protected $finished = false; 
  3.  
  4. protected $identifier = 'aem_async_request'; 
  5.  
  6. public $maxExecutionTime = 30; 
  7.  
  8. public function __construct() 
  9. add_action('wp_ajax_aem_async_request', array ($this, 'maybe_handle')); 
  10. add_action('wp_ajax_nopriv_aem_async_request', array ($this, 'maybe_handle')); 
  11. add_action('aem_async_request', array ($this, 'maybe_handle')); 
  12.  
  13. public function setMaxExecutionTime() 
  14. $max = ini_get('max_execution_time'); 
  15. if ($max) { 
  16. $this->maxExecutionTime = (int)($max * 0.8); 
  17. } else { 
  18. $this->maxExecutionTime = 25; 
  19. error_log($this->maxExecutionTime); 
  20.  
  21. public function schedule() 
  22. $this->next(); 
  23. $this->dispatch(); 
  24.  
  25. public function next() 
  26. wp_schedule_single_event(time() - 5, 'aem_async_request'); 
  27.  
  28. public function handle() 
  29. $this->setStartTime(); 
  30. if ($this->are_we_running()) { 
  31. return; 
  32.  
  33. $this->lockProcess(); 
  34.  
  35. while ($this->canWeProceed() && $this->finished == false) { 
  36. sleep(1); 
  37. $this->task(); 
  38.  
  39. $this->unlockProcess(); 
  40.  
  41. if ($this->finished == false) { 
  42. $this->schedule(); 
  43.  
  44. return; 
  45.  
  46.  
  47. public function canWeProceed() 
  48. error_log($this->maxExecutionTime); 
  49.  
  50. return (($this->startTime + 20 - time()) > 0) ? true : false; 
  51.  
  52. public function task() 
  53. $count = get_site_option('testing_count'); 
  54. if ($count == false) { 
  55. $count = 0; 
  56.  
  57. $count++; 
  58.  
  59. update_site_option('testing_count', $count); 
  60.  
  61. error_log($count); 
  62.  
  63. if ($count >= 100) { 
  64. $this->finished = true; 
  65. delete_site_option('testing_count'); 
  66.  
  67. /** 
  68. * @return int 
  69. */ 
  70. public function elapsedTime() 
  71. return time() - $this->startTime;