class-aw-bg-sync.php 1.3 KB
<?php

class AW_Background_Sync extends aw_WP_Background_Process {

  /**
   * @var string
   */
  protected $action = 'aw_sync_order_to_ac';

  /**
   * Really long running process
   *
   * @return int
   */
  public function really_long_running_task() {
    return sleep( 5 );
  }

  /**
   * Check if the Queue is empty or not
   *
   * @return int
   */
  public function is_empty() {
    return $this->is_queue_empty();
  }

  /**
   * Cancel sync
   *
   * @return int
   */
  public function cancel_sync() {

    $batch = $this->get_batch();
    $batch = $this->delete($batch->key);

    wp_clear_scheduled_hook($this->cron_hook_identifier);

  }


  /**
   * Task
   *
   * Override this method to perform any actions required on each
   * queue item. Return the modified item for further processing
   * in the next pass through. Or, return false to remove the
   * item from the queue.
   *
   * @param mixed $item Queue item to iterate over
   *
   * @return mixed
   */
  protected function task( $order_id ) {

    $this->really_long_running_task();

    aw_add_ac_contact( $order_id );

    return false;
  }

  /**
   * Complete
   *
   * Override if applicable, but ensure that the below actions are
   * performed, or, call parent::complete().
   */
  protected function complete() {
    parent::complete();
  }

}