PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.23
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.23
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Hooks / Scheduler / AutoSchedules / HourlyScheduler.php

HourlyScheduler.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.23, at app/Hooks/Scheduler/AutoSchedules/HourlyScheduler.php

45 lines 982 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Hooks\Scheduler\AutoSchedules;
4
5 use FluentCart\App\Helpers\Status;
6 use FluentCart\App\Models\ScheduledAction;
7 use FluentCart\App\Models\Subscription;
8
9 class HourlyScheduler
10 {
11 private $startTimeStamp = null;
12
13 public function register(): void
14 {
15 add_action('fluent_cart/scheduler/hourly_tasks', [$this, 'handle'], 10);
16 }
17
18 public function handle()
19 {
20 $this->startTimeStamp = time();
21
22 // hourly tasks, remove all completed tasks
23 $this->removeCompleteTasks();
24
25 $this->checkAndExpireSubscriptions();
26 }
27
28
29 private function removeCompleteTasks()
30 {
31 ScheduledAction::query()->where('status', Status::SCHEDULE_COMPLETED)
32 ->limit(5000)
33 ->delete();
34 }
35
36 private function checkAndExpireSubscriptions()
37 {
38 if ((time() - $this->startTimeStamp) > 60) {
39 return;
40 }
41
42 Subscription::checkAndExpireSubscriptions();
43 }
44 }
45