Search in sources :

Example 1 with Repositories

use of com.walmartlabs.concord.server.jooq.tables.Repositories in project concord by walmartlabs.

the class TriggerScheduleDao method findNext.

public TriggerSchedulerEntry findNext() {
    return txResult(tx -> {
        // TODO fetch everything in a single request?
        Map<String, Object> e = tx.select(TRIGGER_SCHEDULE.TRIGGER_ID, TRIGGER_SCHEDULE.FIRE_AT).from(TRIGGER_SCHEDULE).where(TRIGGER_SCHEDULE.FIRE_AT.le(currentOffsetDateTime())).limit(1).forUpdate().skipLocked().fetchOneMap();
        if (e == null) {
            return null;
        }
        UUID id = (UUID) e.get(TRIGGER_SCHEDULE.TRIGGER_ID.getName());
        OffsetDateTime fireAt = (OffsetDateTime) e.get(TRIGGER_SCHEDULE.FIRE_AT.getName());
        Triggers t = TRIGGERS.as("t");
        Projects p = PROJECTS.as("p");
        Repositories r = REPOSITORIES.as("r");
        Organizations o = ORGANIZATIONS.as("o");
        Field<UUID> orgIdField = select(p.ORG_ID).from(p).where(p.PROJECT_ID.eq(t.PROJECT_ID)).asField();
        Record13<UUID, UUID, String, UUID, String, UUID, String, String[], JSONB, JSONB, JSONB, OffsetDateTime, String> record = tx.select(t.TRIGGER_ID, orgIdField, o.ORG_NAME, t.PROJECT_ID, p.PROJECT_NAME, t.REPO_ID, r.REPO_NAME, t.ACTIVE_PROFILES, t.ARGUMENTS, t.TRIGGER_CFG, t.CONDITIONS, currentOffsetDateTime(), t.EVENT_SOURCE).from(t, p, r, o).where(t.TRIGGER_ID.eq(id).and(t.PROJECT_ID.eq(p.PROJECT_ID)).and(p.PROJECT_ID.eq(r.PROJECT_ID)).and(p.ORG_ID.eq(o.ORG_ID)).and(t.REPO_ID.eq(r.REPO_ID))).fetchOne();
        if (record == null) {
            return null;
        }
        UUID triggerId = record.value1();
        UUID orgId = record.value2();
        String organizationName = record.value3();
        UUID projectId = record.value4();
        String projectName = record.value5();
        UUID repoId = record.value6();
        String repositoryName = record.value7();
        List<String> activeProfiles = toList(record.value8());
        Map<String, Object> arguments = objectMapper.fromJSONB(record.value9());
        Map<String, Object> cfg = objectMapper.fromJSONB(record.value10());
        Map<String, Object> conditions = objectMapper.fromJSONB(record.value11());
        OffsetDateTime now = record.value12();
        String eventSource = record.value13();
        TriggerSchedulerEntry result = new TriggerSchedulerEntry(fireAt, triggerId, orgId, organizationName, projectId, projectName, repoId, repositoryName, conditions, cfg, activeProfiles, arguments, eventSource);
        ZoneId zoneId = null;
        if (conditions.get(Constants.Trigger.CRON_TIMEZONE) != null) {
            zoneId = TimeZone.getTimeZone((String) conditions.get(Constants.Trigger.CRON_TIMEZONE)).toZoneId();
        }
        updateFireAt(tx, id, CronUtils.nextExecution(now, (String) conditions.get(Constants.Trigger.CRON_SPEC), zoneId));
        return result;
    });
}
Also used : Repositories(com.walmartlabs.concord.server.jooq.tables.Repositories) ZoneId(java.time.ZoneId) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Triggers(com.walmartlabs.concord.server.jooq.tables.Triggers) OffsetDateTime(java.time.OffsetDateTime) Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations)

Example 2 with Repositories

use of com.walmartlabs.concord.server.jooq.tables.Repositories in project concord by walmartlabs.

the class TriggersDao method selectTriggers.

private SelectJoinStep<Record12<UUID, UUID, String, UUID, String, UUID, String, String, String[], JSONB, JSONB, JSONB>> selectTriggers(DSLContext tx) {
    Organizations o = ORGANIZATIONS.as("o");
    Projects p = PROJECTS.as("p");
    Repositories r = REPOSITORIES.as("r");
    return tx.select(TRIGGERS.TRIGGER_ID, o.ORG_ID, o.ORG_NAME, TRIGGERS.PROJECT_ID, p.PROJECT_NAME, TRIGGERS.REPO_ID, r.REPO_NAME, TRIGGERS.EVENT_SOURCE, TRIGGERS.ACTIVE_PROFILES, TRIGGERS.ARGUMENTS, TRIGGERS.CONDITIONS, TRIGGERS.TRIGGER_CFG).from(TRIGGERS).leftJoin(p).on(p.PROJECT_ID.eq(TRIGGERS.PROJECT_ID)).leftJoin(o).on(o.ORG_ID.eq(p.ORG_ID)).leftJoin(r).on(r.REPO_ID.eq(TRIGGERS.REPO_ID));
}
Also used : Repositories(com.walmartlabs.concord.server.jooq.tables.Repositories) Organizations(com.walmartlabs.concord.server.jooq.tables.Organizations) Projects(com.walmartlabs.concord.server.jooq.tables.Projects)

Aggregations

Organizations (com.walmartlabs.concord.server.jooq.tables.Organizations)2 Projects (com.walmartlabs.concord.server.jooq.tables.Projects)2 Repositories (com.walmartlabs.concord.server.jooq.tables.Repositories)2 Triggers (com.walmartlabs.concord.server.jooq.tables.Triggers)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneId (java.time.ZoneId)1