Skip to content

Commit 5f9137a

Browse files
docs(local): add trigger example and icons (#199)
1 parent 7af2dc2 commit 5f9137a

File tree

7 files changed

+61
-19
lines changed

7 files changed

+61
-19
lines changed

src/main/java/io/kestra/plugin/fs/local/Downloads.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class Downloads extends AbstractLocalTask implements RunnableTask<Downloa
8484
title = "The action to take on downloaded files"
8585
)
8686
@Builder.Default
87-
private Property<Downloads.Action> action = Property.of(Downloads.Action.NONE);
87+
private Property<Downloads.Action> action = Property.ofValue(Downloads.Action.NONE);
8888

8989
@Schema(
9090
title = "The destination directory in case of `MOVE`"
@@ -100,7 +100,7 @@ public class Downloads extends AbstractLocalTask implements RunnableTask<Downloa
100100
title = "List file recursively"
101101
)
102102
@Builder.Default
103-
private Property<Boolean> recursive = Property.of(false);
103+
private Property<Boolean> recursive = Property.ofValue(false);
104104

105105
static void performAction(
106106
String from,
@@ -112,8 +112,8 @@ static void performAction(
112112
Delete delete = Delete.builder()
113113
.id(Delete.class.getSimpleName())
114114
.type(Delete.class.getName())
115-
.from(Property.of(from))
116-
.recursive(Property.of(true))
115+
.from(Property.ofValue(from))
116+
.recursive(Property.ofValue(true))
117117
.build();
118118
delete.run(runContext);
119119
} else if (action == Action.MOVE) {
@@ -124,9 +124,9 @@ static void performAction(
124124
Move move = Move.builder()
125125
.id(Move.class.getSimpleName())
126126
.type(Move.class.getName())
127-
.from(Property.of(from))
127+
.from(Property.ofValue(from))
128128
.to(moveDirectory)
129-
.overwrite(Property.of(true))
129+
.overwrite(Property.ofValue(true))
130130
.build();
131131
move.run(runContext);
132132
}
@@ -139,7 +139,7 @@ public Output run(RunContext runContext) throws Exception {
139139
io.kestra.plugin.fs.local.List listTask = io.kestra.plugin.fs.local.List.builder()
140140
.id(io.kestra.plugin.fs.local.List.class.getSimpleName())
141141
.type(io.kestra.plugin.fs.local.List.class.getName())
142-
.from(Property.of(renderedFrom))
142+
.from(Property.ofValue(renderedFrom))
143143
.regExp(this.regExp)
144144
.recursive(this.recursive)
145145
.build();
@@ -157,7 +157,7 @@ public Output run(RunContext runContext) throws Exception {
157157
Download downloadTask = Download.builder()
158158
.id(Download.class.getSimpleName())
159159
.type(Download.class.getName())
160-
.from(Property.of(fileItem.getLocalPath().toString()))
160+
.from(Property.ofValue(fileItem.getLocalPath().toString()))
161161
.build();
162162

163163
Download.Output downloadOutput = downloadTask.run(runContext);

src/main/java/io/kestra/plugin/fs/local/Trigger.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
package io.kestra.plugin.fs.local;
22

3+
import io.kestra.core.models.annotations.Example;
4+
import io.kestra.core.models.annotations.Plugin;
35
import io.kestra.core.models.conditions.ConditionContext;
46
import io.kestra.core.models.executions.Execution;
57
import io.kestra.core.models.property.Property;
68
import io.kestra.core.models.triggers.*;
79
import io.kestra.core.runners.RunContext;
8-
import io.kestra.core.utils.FileUtils;
910
import io.kestra.plugin.fs.local.models.File;
10-
import io.kestra.plugin.fs.vfs.VfsService;
1111
import io.swagger.v3.oas.annotations.media.Schema;
1212
import jakarta.validation.constraints.NotNull;
1313
import lombok.*;
1414
import lombok.experimental.SuperBuilder;
15-
import org.apache.commons.vfs2.FileType;
16-
import org.slf4j.Logger;
1715

18-
import java.io.IOException;
19-
import java.net.URI;
20-
import java.nio.file.*;
21-
import java.nio.file.attribute.BasicFileAttributes;
2216
import java.time.Duration;
2317
import java.util.*;
24-
import java.util.stream.Stream;
2518

2619
import static io.kestra.core.utils.Rethrow.throwFunction;
2720

@@ -30,6 +23,39 @@
3023
@EqualsAndHashCode
3124
@Getter
3225
@NoArgsConstructor
26+
@Schema(
27+
title = "Trigger a flow as soon as new files are detected in a given local file system's directory."
28+
)
29+
@Plugin(
30+
examples = {
31+
@Example(
32+
title = "Wait for one or more files in a given local file system's directory and process each of these files sequentially.",
33+
full = true,
34+
code = """
35+
id: local_trigger_flow
36+
namespace: company.team
37+
38+
tasks:
39+
- id: for_each_file
40+
type: io.kestra.plugin.core.flow.ForEach
41+
values: "{{ trigger.files }}"
42+
tasks:
43+
- id: return
44+
type: io.kestra.plugin.core.debug.Return
45+
format: "{{ taskrun.value | jq('.path') }}"
46+
47+
triggers:
48+
- id: watch
49+
type: io.kestra.plugin.fs.local.Trigger
50+
from: "/home/dev/kestra"
51+
interval: PT10S
52+
action: MOVE
53+
recursive: true
54+
moveDirectory: "/home/dev/archive/"
55+
"""
56+
)
57+
}
58+
)
3359
public class Trigger extends AbstractTrigger implements PollingTriggerInterface, TriggerOutput<Downloads.Output> {
3460

3561
@Schema(title = "The interval between checks")
@@ -52,13 +78,13 @@ public class Trigger extends AbstractTrigger implements PollingTriggerInterface,
5278

5379
@Schema(title = "Include files in subdirectories")
5480
@Builder.Default
55-
private Property<Boolean> recursive = Property.of(false);
81+
private Property<Boolean> recursive = Property.ofValue(false);
5682

5783
@Schema(
5884
title = "The action to do on downloaded files"
5985
)
6086
@Builder.Default
61-
private Property<Downloads.Action> action = Property.of(Downloads.Action.NONE);
87+
private Property<Downloads.Action> action = Property.ofValue(Downloads.Action.NONE);
6288

6389
@Override
6490
public Optional<Execution> evaluate(ConditionContext conditionContext, TriggerContext triggerContext) throws Exception {
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)