Passed
Push — master ( cb93ae...a071e0 )
by Marcel
03:58
created

EndOfDay::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
rs 10
1
<?php
2
/**
3
 * Analytics
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2019-2022 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\BackgroundJob;
13
14
use OCA\Analytics\Service\DataloadService;
15
use OCP\AppFramework\Utility\ITimeFactory;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Utility\ITimeFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use OCP\BackgroundJob\TimedJob;
0 ignored issues
show
Bug introduced by
The type OCP\BackgroundJob\TimedJob was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
class EndOfDay extends TimedJob
20
{
21
22
    private $logger;
23
    private $DataloadService;
24
25
    public function __construct(ITimeFactory $time,
26
                                LoggerInterface $logger,
27
                                DataloadService $DataloadService
28
    )
29
    {
30
        parent::__construct($time);
31
        $this->setInterval(60 * 10); // Check every 10 minutes to ensure it hits the 15 min window once
32
        $this->logger = $logger;
33
        $this->DataloadService = $DataloadService;
34
    }
35
36
    public function run($arguments)
37
    {
38
        $currentTime = new \DateTime(); // Current time
39
        $endOfDay = new \DateTime('today 23:59:59'); // End of the day
40
        $startOfLast15Minutes = (clone $endOfDay)->modify('-15 minutes'); // Start of last 15 minutes of the day
41
42
        if ($currentTime >= $startOfLast15Minutes && $currentTime <= $endOfDay) {
43
            try {
44
                $this->logger->debug('Analytics Dataload - End of day');
45
                $this->DataloadService->executeBySchedule('e');
46
            } catch (\Exception $e) {
47
                // Handle exception or log error
48
            }
49
        }
50
    }
51
52
}