Skip to content

Commit

Permalink
chore(version): update to version 'v0.4.7'.
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Jun 8, 2022
2 parents 8cec35f + 40efdcb commit 9676675
Show file tree
Hide file tree
Showing 22 changed files with 213 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ body:
value: |
Thanks for reporting an issue, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.
NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on [Github Discussions](https://github.com/kestra-io/kestra/discussions) or [Discord](https://discord.gg/NMG39WKGth).
NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on [Github Discussions](https://github.com/kestra-io/kestra/discussions) or [Slack](https://join.slack.com/t/kestra-io/shared_invite/zt-193shv281-rK9QOEfZC2_vEbDO7Uxtbw).
- type: textarea
attributes:
label: Expected Behavior
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ contact_links:
url: https://github.com/kestra-io/kestra/discussions
about: Ask questions about Kestra on Github
- name: Chat
url: https://discord.gg/NMG39WKGth
about: Chat with us on Discord.
url: https://join.slack.com/t/kestra-io/shared_invite/zt-193shv281-rK9QOEfZC2_vEbDO7Uxtbw
about: Chat with us on Slack.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -58,7 +58,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -72,4 +72,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
packages: ""
- name: "-full"
plugins: io.kestra.storage:storage-azure:LATEST io.kestra.storage:storage-gcs:LATEST io.kestra.storage:storage-minio:LATEST io.kestra.plugin:plugin-aws:LATEST io.kestra.plugin:plugin-azure:LATEST io.kestra.plugin:plugin-cassandra:LATEST io.kestra.plugin:plugin-compress:LATEST io.kestra.plugin:plugin-crypto:LATEST io.kestra.plugin:plugin-dbt:LATEST io.kestra.plugin:plugin-debezium-mysql:LATEST io.kestra.plugin:plugin-debezium-postgres:LATEST io.kestra.plugin:plugin-debezium-sqlserver:LATEST io.kestra.plugin:plugin-elasticsearch:LATEST io.kestra.plugin:plugin-fs:LATEST io.kestra.plugin:plugin-gcp:LATEST io.kestra.plugin:plugin-googleworkspace:LATEST io.kestra.plugin:plugin-jdbc-clickhouse:LATEST io.kestra.plugin:plugin-jdbc-mysql:LATEST io.kestra.plugin:plugin-jdbc-oracle:LATEST io.kestra.plugin:plugin-jdbc-postgres:LATEST io.kestra.plugin:plugin-jdbc-redshift:LATEST io.kestra.plugin:plugin-jdbc-snowflake:LATEST io.kestra.plugin:plugin-jdbc-sqlserver:LATEST io.kestra.plugin:plugin-jdbc-vertica:LATEST io.kestra.plugin:plugin-jdbc-vectorwise:LATEST io.kestra.plugin:plugin-kafka:LATEST io.kestra.plugin:plugin-kubernetes:LATEST io.kestra.plugin:plugin-mongodb:LATEST io.kestra.plugin:plugin-mqtt:LATEST io.kestra.plugin:plugin-notifications:LATEST io.kestra.plugin:plugin-script-groovy:LATEST io.kestra.plugin:plugin-script-jython:LATEST io.kestra.plugin:plugin-script-nashorn:LATEST io.kestra.plugin:plugin-serdes:LATEST io.kestra.plugin:plugin-singer:LATEST io.kestra.plugin:plugin-spark:LATEST
packages: python3-pip python3-wheel python3-setuptools python3-virtualenv python-is-python3 nodejs curl wait-for-it zip unzip
packages: python3 python3-venv python-is-python3 nodejs curl wait-for-it zip unzip
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -167,24 +167,24 @@ jobs:
# Docker setup
- name: Set up QEMU
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/v')
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/v')
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

# Docker Login
- name: Login to DockerHub
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# Docker Build and push
- name: Push to Docker Hub
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: .
push: true
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<a href="https://hub.docker.com/r/kestra/kestra"><img src="https://img.shields.io/docker/pulls/kestra/kestra.svg?style=flat-square" alt="Docker pull" /></a>
<a href="https://artifacthub.io/packages/helm/kestra/kestra"><img src="https://img.shields.io/badge/Artifact%20Hub-kestra-417598?style=flat-square&logo=artifacthub" alt="Artifact Hub" /></a>
<a href="https://kestra.io"><img src="https://img.shields.io/badge/Website-kestra.io-192A4E?style=flat-square" alt="Kestra infinitely scalable orchestration and scheduling platform"></a>
<a href="https://discord.gg/5RgZmkW"><img src="https://img.shields.io/discord/903344083391631471?label=Discord&style=flat-square" alt="Discord"></a>
<a href="https://join.slack.com/t/kestra-io/shared_invite/zt-193shv281-rK9QOEfZC2_vEbDO7Uxtbw"><img src="https://img.shields.io/badge/Slack-chat-400d40?style=flat-square&logo=slack" alt="Slack"></a>
<a href="https://github.com/kestra-io/kestra/discussions"><img src="https://img.shields.io/github/discussions/kestra-io/kestra?style=flat-square" alt="Github discussions"></a>
<a href="https://twitter.com/kestra_io"><img src="https://img.shields.io/twitter/follow/kestra_io?style=flat-square" alt="Twitter" /></a>
<a href="https://app.codecov.io/gh/kestra-io/kestra"><img src="https://img.shields.io/codecov/c/github/kestra-io/kestra?style=flat-square&token=It6L7BTaWK" alt="Code Cov" /></a>
Expand All @@ -29,7 +29,7 @@
<a href="https://kestra.io/"><b>Website</b></a> •
<a href="https://twitter.com/kestra_io"><b>Twitter</b></a> •
<a href="https://www.linkedin.com/company/kestra/"><b>Linked In</b></a> •
<a href="https://discord.gg/NMG39WKGth"><b>Discord</b></a> •
<a href="https://join.slack.com/t/kestra-io/shared_invite/zt-193shv281-rK9QOEfZC2_vEbDO7Uxtbw"><b>Slack</b></a> •
<a href="https://kestra.io/docs/"><b>Documentation</b></a>
</p>

Expand Down Expand Up @@ -245,7 +245,7 @@ Join our community if you need help, want to chat or have any other questions fo

- [GitHub](https://github.com/kestra-io/kestra/discussions) - Discussion forums and updates from the Kestra team
- [Twitter](https://twitter.com/kestra_io) - For all the latest Kestra news
- [Discord](https://discord.gg/NMG39WKGth) - Join the conversation! Get all the latest updates and chat to the devs
- [Slack](https://join.slack.com/t/kestra-io/shared_invite/zt-193shv281-rK9QOEfZC2_vEbDO7Uxtbw) - Join the conversation! Get all the latest updates and chat to the devs


## Roadmap
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

// test
id 'com.adarshr.test-logger' version '3.2.0'
id 'org.gradle.test-retry' version '1.3.1'
id 'org.gradle.test-retry' version '1.4.0'

// helper
id "com.github.ben-manes.versions" version "0.42.0"
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
testImplementation project(':runner-memory')
testImplementation project(':storage-local')

testImplementation 'org.mockito:mockito-junit-jupiter:4.4.0'
testImplementation 'org.mockito:mockito-junit-jupiter:4.5.1'
testImplementation "io.micronaut:micronaut-http-client"
testImplementation "io.micronaut.rxjava2:micronaut-rxjava2-http-client"
testImplementation "io.micronaut:micronaut-http-server-netty"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@EqualsAndHashCode
@Getter
@NoArgsConstructor
@io.kestra.core.validations.Schedule
@Schema(
title = "Schedule a flow based on cron date",
description = "Kestra is able to trigger flow based on Schedule (aka the time). If you need to wait another system " +
Expand Down Expand Up @@ -116,13 +117,21 @@ public class Schedule extends AbstractTrigger implements PollingTriggerInterface
@PluginProperty(dynamic = true)
private Map<String, String> inputs;

@Schema(
title = "The maximum late delay accepted",
description = "If the schedule didn't start after this delay, the execution will be skip."
)
private Duration lateMaximumDelay;

@Getter(AccessLevel.NONE)
private transient ExecutionTime executionTime;

@Override
public ZonedDateTime nextEvaluationDate(ConditionContext conditionContext, Optional<? extends TriggerContext> last) {
ExecutionTime executionTime = this.executionTime();

// previous present & scheduleConditions
if (last.isPresent() && this.scheduleConditions != null) {

Optional<ZonedDateTime> next = this.truePreviousNextDateWithCondition(
executionTime,
conditionContext,
Expand Down Expand Up @@ -152,7 +161,12 @@ public ZonedDateTime nextEvaluationDate(ConditionContext conditionContext, Optio
public Optional<Execution> evaluate(ConditionContext conditionContext, TriggerContext context) throws Exception {
RunContext runContext = conditionContext.getRunContext();
ExecutionTime executionTime = this.executionTime();
Output output = this.output(executionTime, context.getDate()).orElse(null);
ZonedDateTime previousDate = context.getDate();

Output output = this.output(executionTime, previousDate).orElse(null);

// if max delay reach, we calculate a new date
output = this.handleMaxDelay(output);

if (output == null || output.getDate() == null) {
return Optional.empty();
Expand All @@ -161,7 +175,7 @@ public Optional<Execution> evaluate(ConditionContext conditionContext, TriggerCo
ZonedDateTime next = output.getDate();

// we try at the exact time / standard behaviour
boolean isReady = next.compareTo(context.getDate()) == 0;
boolean isReady = next.compareTo(previousDate) == 0;

// in case on cron expression changed, the next date will never match, so we allow past operation to start
boolean isLate = next.compareTo(ZonedDateTime.now().minus(Duration.ofMinutes(1))) < 0;
Expand All @@ -175,6 +189,8 @@ public Optional<Execution> evaluate(ConditionContext conditionContext, TriggerCo
return Optional.empty();
}



// inject outputs variables for scheduleCondition
conditionContext = conditionContext(conditionContext, output);

Expand Down Expand Up @@ -244,10 +260,14 @@ private ConditionContext conditionContext(ConditionContext conditionContext, Out
));
}

private ExecutionTime executionTime() {
Cron parse = CRON_PARSER.parse(this.cron);
private synchronized ExecutionTime executionTime() {
if (this.executionTime == null) {
Cron parse = CRON_PARSER.parse(this.cron);

this.executionTime = ExecutionTime.forCron(parse);
}

return ExecutionTime.forCron(parse);
return this.executionTime;
}

private Optional<ZonedDateTime> computeNextEvaluationDate(ExecutionTime executionTime, ZonedDateTime date) {
Expand Down Expand Up @@ -299,6 +319,32 @@ private Optional<ZonedDateTime> truePreviousNextDateWithCondition(ExecutionTime
return Optional.empty();
}

private Output handleMaxDelay(Output output) {
if (output == null) {
return null;
}

if (this.lateMaximumDelay == null) {
return output;
}

while (
(output.getDate().getYear() < ZonedDateTime.now().getYear() + 10) ||
(output.getDate().getYear() > ZonedDateTime.now().getYear() - 10)
) {
if (output.getDate().plus(this.lateMaximumDelay).compareTo(ZonedDateTime.now()) < 0) {
output = this.output(executionTime, output.getNext()).orElse(null);
if (output == null) {
return null;
}
} else {
return output;
}
}

return output;
}

private boolean validateScheduleCondition(ConditionContext conditionContext) {
if (scheduleConditions != null) {
ConditionService conditionService = conditionContext.getRunContext().getApplicationContext().getBean(ConditionService.class);
Expand Down
25 changes: 21 additions & 4 deletions core/src/main/java/io/kestra/core/runners/pebble/AbstractDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.FormatStyle;
import java.util.*;

Expand Down Expand Up @@ -102,10 +103,26 @@ protected static ZonedDateTime convert(Object value, ZoneId zoneId, String exist
return Instant.ofEpochSecond((Long) value).atZone(zoneId);
}

if (existingFormat != null) {
return ZonedDateTime.parse((String) value, formatter(existingFormat));
try {
if (existingFormat != null) {
return ZonedDateTime.parse((String) value, formatter(existingFormat));
} else {
return ZonedDateTime.parse((String) value);
}
} catch (DateTimeParseException e) {
try {
if (existingFormat != null) {
return LocalDateTime.parse((String) value, formatter(existingFormat)).atZone(zoneId);
} else {
return LocalDateTime.parse((String) value).atZone(zoneId);
}
} catch (DateTimeParseException e2) {
if (existingFormat != null) {
return LocalDate.parse((String) value, formatter(existingFormat)).atStartOfDay().atZone(zoneId);
} else {
return LocalDate.parse((String) value).atStartOfDay().atZone(zoneId);
}
}
}

return ZonedDateTime.parse((String) value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected String virtualEnvCommand(RunContext runContext, List<String> requireme
}

renderer.addAll(Arrays.asList(
this.pythonPath + " -m venv " + workingDirectory + " > /dev/null",
this.pythonPath + " -m venv --system-site-packages " + workingDirectory + " > /dev/null",
"./bin/pip install pip --upgrade > /dev/null",
requirementsAsString
));
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/io/kestra/core/validations/Schedule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.kestra.core.validations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.validation.Constraint;

@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = { })
public @interface Schedule {
String message() default "invalid schedule ({validatedValue})";
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ ConstraintValidator<CronExpression, CharSequence> cronExpressionValidator() {
};
}


@Singleton
ConstraintValidator<Schedule, io.kestra.core.models.triggers.types.Schedule> scheduleValidator() {
return (value, annotationMetadata, context) -> {
if (value == null) {
return true;
}

if (value.getBackfill() != null && value.getBackfill().getStart() != null && value.getLateMaximumDelay() != null) {
context.messageTemplate("invalid schedule: backfill and lateMaximumDelay are incompatible options");

return false;
}

return true;
};
}


@Singleton
ConstraintValidator<JsonString, String> jsonStringValidator() {
return (value, annotationMetadata, context) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,33 @@ void conditionsWithBackfill() throws Exception {
}
}


@SuppressWarnings("unchecked")
@Test
void lateMaximumDelay() throws Exception {
Schedule trigger = Schedule.builder()
.cron("* * * * *")
.lateMaximumDelay(Duration.ofMinutes(5))
.build();

ZonedDateTime date = ZonedDateTime.now().minusMinutes(15);
ZonedDateTime expected = ZonedDateTime.now().minusMinutes(4)
.withSecond(0)
.truncatedTo(ChronoUnit.SECONDS);

Optional<Execution> evaluate = trigger.evaluate(
conditionContext(),
TriggerContext.builder()
.date(date)
.build()
);

assertThat(evaluate.isPresent(), is(true));
var vars = (Map<String, String>) evaluate.get().getVariables().get("schedule");
assertThat(dateFromVars(vars.get("date"), date), is(expected));

}

private ConditionContext conditionContext() {
return ConditionContext.builder()
.runContext(runContextFactory.of())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;

import jakarta.inject.Inject;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -49,6 +51,23 @@ void dateFormat() throws IllegalVariableEvaluationException {
));
}

@Test
void dateStringFormat() throws IllegalVariableEvaluationException {
String render = variableRenderer.render(
"{{ \"July 24, 2001\" | date(\"yyyy-MM-dd\", existingFormat=\"MMMM dd, yyyy\") }}\n" +
"{{ \"2013-09-08T17:19:12+02:00\" | date(timeZone=\"Europe/Paris\") }}\n" +
"{{ \"2013-09-08T17:19:12\" | date(timeZone=\"Europe/Paris\") }}\n" +
"{{ \"2013-09-08\" | date(timeZone=\"Europe/Paris\") }}\n",
Map.of()
);

assertThat(render, is("2001-07-24\n" +
"2013-09-08T17:19:12.000000+02:00\n" +
"2013-09-08T17:19:12.000000+02:00\n" +
"2013-09-08T00:00:00.000000+02:00\n"
));
}

@Test
void timestamp() throws IllegalVariableEvaluationException {
String render = variableRenderer.render(
Expand Down
Loading

0 comments on commit 9676675

Please sign in to comment.