Queue.php
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace WP_Rocket\Engine\Preload\Controller;
use ActionScheduler_Store;
use WP_Rocket\Engine\Common\Queue\AbstractASQueue;
class Queue extends AbstractASQueue {
/**
* Group from the queue.
*
* @var string
*/
protected $group = 'rocket-preload';
/**
* Add Async load initial sitemap job.
*
* @return string
*/
public function add_job_preload_job_load_initial_sitemap_async() {
return $this->add_async( 'rocket_preload_job_load_initial_sitemap' );
}
/**
* Add Async parse sitemap job with url.
*
* @param string $sitemap_url sitemap url.
*
* @return string
*/
public function add_job_preload_job_parse_sitemap_async( string $sitemap_url ) {
return $this->add_async(
'rocket_preload_job_parse_sitemap',
[
$sitemap_url,
]
);
}
/**
* Add Async preload url job with url.
*
* @param string $url url to preload.
*
* @return string
*/
public function add_job_preload_job_preload_url_async( string $url ) {
return $this->add_async(
'rocket_preload_job_preload_url',
[
$url,
]
);
}
/**
* Add a job that check if the preload is finished.
*
* @return string
*/
public function add_job_preload_job_check_finished_async() {
if ( $this->job_preload_job_check_finished_async_exists() ) {
return '';
}
return $this->schedule_single( time() + MINUTE_IN_SECONDS, 'rocket_preload_job_check_finished', [ time() ] );
}
/**
* Check if a task job_preload_job_check_finished_async_exists already exists.
*
* @return bool
*/
public function job_preload_job_check_finished_async_exists() {
$row_found = $this->search(
[
'hook' => 'rocket_preload_job_check_finished',
'status' => ActionScheduler_Store::STATUS_PENDING,
],
'ids'
);
return count( $row_found ) > 0;
}
/**
* Check if some task is remaining.
*
* @return bool
*/
public function has_remaining_tasks() {
$parse_sitemap = $this->search(
[
'hook' => 'rocket_preload_job_parse_sitemap',
'status' => ActionScheduler_Store::STATUS_PENDING,
],
'ids'
);
$preload_url = $this->search(
[
'hook' => 'rocket_preload_job_preload_url',
'status' => ActionScheduler_Store::STATUS_PENDING,
],
'ids'
);
return count( $parse_sitemap ) > 0 || count( $preload_url ) > 0;
}
/**
* Cancel pending jobs.
*
* @return void
*/
public function cancel_pending_jobs() {
$this->cancel_all( '' );
}
}