advisor.php
2 years ago
chatbot.php
1 year ago
discussions.php
1 year ago
files.php
2 years ago
gdpr.php
1 year ago
security.php
2 years ago
tasks.php
2 years ago
wand.php
2 years ago
tasks.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Modules_Tasks { |
| 4 | private $core = null; |
| 5 | private $wpdb = null; |
| 6 | private $namespace = 'mwai-ui/v1'; |
| 7 | private $db_check = false; |
| 8 | private $table_tasks = null; |
| 9 | private $table_taskmeta = null; |
| 10 | private $dev_mode = false; |
| 11 | |
| 12 | public function __construct( $core ) { |
| 13 | global $wpdb; |
| 14 | $this->core = $core; |
| 15 | $this->wpdb = $wpdb; |
| 16 | //$this->dev_mode = defined('MEOWAPPS_DEV_MODE') && MEOWAPPS_DEV_MODE; |
| 17 | // $this->table_tasks = $this->wpdb->prefix . 'mwai_tasks'; |
| 18 | // $this->table_taskmeta = $this->wpdb->prefix . 'mwai_taskmeta'; |
| 19 | add_filter( 'cron_schedules', [ $this, 'custom_cron_schedule' ] ); |
| 20 | |
| 21 | // Let's add a dev mode, to run tasks every 5 seconds |
| 22 | if ( $this->dev_mode ) { |
| 23 | if ( !wp_next_scheduled( 'mwai_tasks_internal_dev_run' ) ) { |
| 24 | wp_schedule_event( time(), 'mwai_5sec', 'mwai_tasks_internal_dev_run' ); |
| 25 | } |
| 26 | add_action( 'mwai_tasks_internal_dev_run', [ $this, 'run_tasks' ] ); |
| 27 | } |
| 28 | else { |
| 29 | if ( !wp_next_scheduled( 'mwai_tasks_internal_run' ) ) { |
| 30 | wp_schedule_event( time(), 'mwai_5mn', 'mwai_tasks_internal_run' ); |
| 31 | } |
| 32 | add_action( 'mwai_tasks_internal_run', [ $this, 'run_tasks' ] ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | function custom_cron_schedule( $schedules ) { |
| 37 | $schedules['mwai_5mn'] = array( 'display' => __( 'Every 5 Minute' ), 'interval' => 300 ); |
| 38 | if ( $this->dev_mode ) { |
| 39 | $schedules['mwai_5sec'] = array( 'display' => __( 'Every 5 Second' ), 'interval' => 5 ); |
| 40 | } |
| 41 | return $schedules; |
| 42 | } |
| 43 | |
| 44 | function run_tasks() { |
| 45 | do_action( 'mwai_tasks_run' ); |
| 46 | } |
| 47 | |
| 48 | // Later we can create a table for the tasks (and taskmeta) for tasks |
| 49 | // which has to be ran only once, and then deleted. |
| 50 | } |
| 51 |