scheduler = $scheduler; } /** * Check if a job name is used for product syncing. * * @param string $hook * * @return bool */ protected function job_matches( string $hook ): bool { foreach ( self::MATCHES as $match ) { if ( false !== stripos( $hook, $match ) ) { return true; } } return false; } /** * Return the amount of product sync jobs which are pending. * * @return int */ public function get_count(): int { $count = 0; $scheduled = $this->scheduler->search( [ 'status' => 'pending', 'per_page' => -1, ] ); foreach ( $scheduled as $action ) { if ( $this->job_matches( $action->get_hook() ) ) { ++$count; } } return $count; } }