feat(system): add a lock mechanism

This commit is contained in:
Loïc Mathieu
2025-10-20 12:43:53 +02:00
parent 0df41b439d
commit d5ba7e7304
18 changed files with 687 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
package io.kestra.repository.postgres;
import io.kestra.core.lock.Lock;
import io.kestra.jdbc.AbstractJdbcRepository;
import io.kestra.jdbc.repository.AbstractJdbcLockRepository;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
@Singleton
@PostgresRepositoryEnabled
public class PostgresLockRepository extends AbstractJdbcLockRepository {
public PostgresLockRepository(@Named("locks") AbstractJdbcRepository<Lock> jdbcRepository) {
super(jdbcRepository);
}
}

View File

@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS locks (
key VARCHAR(250) NOT NULL PRIMARY KEY,
value JSONB NOT NULL,
category VARCHAR(250) NOT NULL GENERATED ALWAYS AS (value ->> 'category') STORED,
id VARCHAR(150) NOT NULL GENERATED ALWAYS AS (value ->> 'id') STORED,
owner VARCHAR(150) NOT NULL GENERATED ALWAYS AS (value ->> 'owner') STORED
);
CREATE INDEX IF NOT EXISTS locks__catefory_id ON locks (category, id);

View File

@@ -0,0 +1,6 @@
package io.kestra.repository.postgres;
import io.kestra.core.repositories.AbstractLockRepositoryTest;
public class PostgresRepositoryTest extends AbstractLockRepositoryTest {
}