diff --git a/appinfo/info.xml b/appinfo/info.xml
index 768b23e..502cb6b 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -13,7 +13,7 @@ The OpenConnector Nextcloud app provides a ESB-framework to work together in an
- 🆓 Map and translate API calls
]]>
- 0.1.20
+ 0.1.21
agpl
integration
Conduction
@@ -33,6 +33,10 @@ The OpenConnector Nextcloud app provides a ESB-framework to work together in an
+
+ OCA\OpenConnector\Cron\LogCleanUpTask
+
+
openconnector
diff --git a/lib/Cron/ActionTask.php b/lib/Cron/ActionTask.php
index 471f186..0ad5a34 100644
--- a/lib/Cron/ActionTask.php
+++ b/lib/Cron/ActionTask.php
@@ -109,7 +109,9 @@ public function run($argument)
// Update the job
$job->setLastRun(new DateTime());
- $job->setNextRun(new DateTime());
+ $nextRun = new DateTime('now + '.$job->getInterval().' seconds');
+ $nextRun->setTime(hour: $nextRun->format('H'), minute: $nextRun->format('i'));
+ $job->setNextRun($nextRun);
$this->jobMapper->update($job);
// Log the job
diff --git a/lib/Cron/LogCleanUpTask.php b/lib/Cron/LogCleanUpTask.php
index 0af048a..0aa7cf3 100644
--- a/lib/Cron/LogCleanUpTask.php
+++ b/lib/Cron/LogCleanUpTask.php
@@ -3,13 +3,35 @@
namespace OCA\OpenConnector\Cron;
use OCA\OpenConnector\Db\CallLogMapper;
+use OCA\OpenConnector\Db\JobLogMapper;
+use OCA\OpenConnector\Db\JobMapper;
+use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IUserManager;
+use OCP\IUserSession;
-class LogCleanUpTask
+class LogCleanUpTask extends TimedJob
{
- public function doCron(array $arguments, CallLogMapper $callLogMapper){
- $callLogMapper = new ClearLogs();
+ public function __construct(
+ ITimeFactory $time,
+ private readonly CallLogMapper $callLogMapper,
+ ) {
+ parent::__construct($time);
+
+ // Run every 5 minutes
+ $this->setInterval(300);
+
+ // Delay until low-load time
+ //$this->setTimeSensitivity(\OCP\BackgroundJob\IJob::TIME_SENSITIVE);
+ // Or $this->setTimeSensitivity(\OCP\BackgroundJob\IJob::TIME_INSENSITIVE);
+
+ // Only run one instance of this job at a time
+ $this->setAllowParallelRuns(false);
+ }
+
+ public function run(mixed $argument){
+ $this->callLogMapper->clearLogs();
}
}
diff --git a/lib/Db/CallLogMapper.php b/lib/Db/CallLogMapper.php
index 49cac82..615b5bb 100644
--- a/lib/Db/CallLogMapper.php
+++ b/lib/Db/CallLogMapper.php
@@ -93,7 +93,7 @@ public function clearLogs(): bool
// Build the delete query
$qb->delete('openconnector_call_logs')
- ->where($qb->expr()->lt('expired', $qb->createFunction('NOW()')));
+ ->where($qb->expr()->lt('expires', $qb->createFunction('NOW()')));
// Execute the query and get the number of affected rows
$result = $qb->execute();
diff --git a/lib/Migration/Version1Date20241206095007.php b/lib/Migration/Version1Date20241206095007.php
new file mode 100644
index 0000000..d26a0c8
--- /dev/null
+++ b/lib/Migration/Version1Date20241206095007.php
@@ -0,0 +1,66 @@
+hasTable('openconnector_sources') === true) {
+ $table = $schema->getTable('openconnector_sources');
+
+ if ($table->hasColumn('logRetention') === true) {
+ $table->dropColumn('logRetention');
+ $table->addColumn('log_retention', Types::INTEGER)->setNotnull(false)->setDefault(3600);
+ }
+ if ($table->hasColumn('errorRetention') === true) {
+ $table->dropColumn('errorRetention');
+ $table->addColumn('error_retention', Types::INTEGER)->setNotnull(false)->setDefault(86400);
+ }
+ }
+
+ return $schema;
+ }
+
+ /**
+ * @param IOutput $output
+ * @param Closure(): ISchemaWrapper $schemaClosure
+ * @param array $options
+ */
+ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
+ }
+}
diff --git a/lib/Service/CallService.php b/lib/Service/CallService.php
index e40bc95..8db6434 100644
--- a/lib/Service/CallService.php
+++ b/lib/Service/CallService.php
@@ -138,6 +138,7 @@ public function call(
$callLog->setStatusCode(409);
$callLog->setStatusMessage("This source is not enabled");
$callLog->setCreated(new \DateTime());
+ $callLog->setExpires(new \DateTime('now + '.$source->getErrorRetention().' seconds'));
$this->callLogMapper->insert($callLog);
@@ -152,6 +153,7 @@ public function call(
$callLog->setStatusCode(409);
$callLog->setStatusMessage("This source has no location");
$callLog->setCreated(new \DateTime());
+ $callLog->setExpires(new \DateTime('now + '.$source->getErrorRetention().' seconds'));
$this->callLogMapper->insert($callLog);
@@ -178,6 +180,7 @@ public function call(
$callLog->setStatusCode(429); //
$callLog->setStatusMessage("The rate limit for this source has been exceeded. Try again later.");
$callLog->setCreated(new \DateTime());
+ $callLog->setExpires(new \DateTime('now + '.$source->getErrorRetention().' seconds'));
$this->callLogMapper->insert($callLog);
@@ -282,6 +285,7 @@ public function call(
$callLog->setRequest($data['request']);
$callLog->setResponse($data['response']);
$callLog->setCreated(new \DateTime());
+ $callLog->setExpires(new \DateTime('now + '.($data['response']['statusCode'] < 400 ? $source->getLogRetention() : $source->getErrorRetention()).' seconds'));
$this->callLogMapper->insert($callLog);