public static boolean isBackupCronTime()

in services/library/src/main/java/com/google/cloud/pso/bq_snapshot_manager/functions/f02_configurator/Configurator.java [327:382]


    public static boolean isBackupCronTime(
            TableSpec targetTable,
            String cron,
            Timestamp referencePoint,
            BackupConfigSource configSource,
            Timestamp lastBackupAt,
            LoggingHelper logger,
            String trackingId
    ) {

        boolean takeBackup;

        if (configSource.equals(BackupConfigSource.SYSTEM)
                && lastBackupAt == null) {
            // this means the table has not been backed up before
            // CASE 1: It's a fallback configuration (SYSTEM) running for the first time --> take backup
            takeBackup = true;
        } else {

            if (lastBackupAt == null) {
                // this means the table has not been backed up before
                // CASE 2: It's a MANUAL config but running for the first time
                takeBackup = true;
            } else {

                // CASE 3: It's MANUAL OR SYSTEM config that ran before and already attached to the table
                // --> decide based on CRON next trigger check

                Tuple<Boolean, LocalDateTime> takeBackupTuple = getCronNextTrigger(
                        cron,
                        lastBackupAt,
                        referencePoint
                );

                // .x() is a boolean flag to take a backup or not
                // .y() is the calculated next cron date used in the comparison
                if (takeBackupTuple.x()) {
                    takeBackup = true;
                    logger.logInfoWithTracker(
                            trackingId,
                            targetTable,
                            String.format("Will backup table %s at this run. Calculated next backup time is %s and this run is %s",
                                    targetTable.toSqlString(), takeBackupTuple.y(), referencePoint));

                } else {
                    takeBackup = false;
                    logger.logInfoWithTracker(
                            trackingId,
                            targetTable,
                            String.format("Will skip backup for table %s at this run. Calculated next backup time is %s and this run is %s",
                                    targetTable.toSqlString(), takeBackupTuple.y(), referencePoint));
                }
            }
        }
        return takeBackup;
    }