Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,23 @@ public Set<EnvKey> dependents() {
@Override
void onHandle(Node node, String value) {
try {
new CronExpression(value);
// fill seconds to crontab value
String valueWithSeconds = "0 " + value;
node.putEnv(env(), valueWithSeconds);
new CronExpression(valueWithSeconds);

// setup crontab task
// setup new value and crontab task
nodeCrontabService.set(node);
} catch (ParseException e) {
throw new IllegalParameterException("Illegal FLOW_TASK_CRONTAB_CONTENT format: " + e.getMessage());
} finally {
// reset value to original
node.putEnv(env(), value);
}
}

@Override
void onUnHandle(Node node, String value) {
nodeCrontabService.delete(node);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void initHandlers() {
@Test
public void should_handle_crontab_variable() throws Throwable {
Node node = new Node("flow", "flow");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT, "0 0/30 * * * ?");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT, "0/30 * * * ?");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_BRANCH, "master");

EnvHandler envHandler = handlerMap.get(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT);
Expand All @@ -61,7 +61,7 @@ public void should_handle_crontab_variable() throws Throwable {
@Test(expected = IllegalParameterException.class)
public void should_raise_exception_when_missing_dependent_env_var() throws Throwable {
Node node = new Node("flow", "flow");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT, "* * * * * ?");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT, "* * * * ?");

EnvHandler envHandler = handlerMap.get(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT);
envHandler.handle(node);
Expand All @@ -70,7 +70,7 @@ public void should_raise_exception_when_missing_dependent_env_var() throws Throw
@Test(expected = IllegalParameterException.class)
public void should_raise_exception_when_incorrect_crontab_format() throws Throwable {
Node node = new Node("flow", "flow");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT, "* * * * * *");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT, "* * * * *");
node.putEnv(FlowEnvs.FLOW_TASK_CRONTAB_BRANCH, "master");

EnvHandler envHandler = handlerMap.get(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,21 @@ public void should_start_job_when_set_crontab_for_flow() throws Throwable {

Map<String, String> envs = new HashMap<>();
envs.put(FlowEnvs.FLOW_TASK_CRONTAB_BRANCH.name(), "master");
envs.put(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT.name(), "0/10 * * * * ?");
envs.put(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT.name(), "0/1 * * * ?");
envService.save(flow, envs, true);

Assert.assertNotNull(flow.getEnv(FlowEnvs.FLOW_TASK_CRONTAB_BRANCH));
Assert.assertNotNull(flow.getEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT));

// when: set crontab task for flow and wait for 30 seconds
flowCrontabService.set(flow);
Thread.sleep(15 * 1000);
// when: set crontab task for flow and wait for 70 seconds
Thread.sleep(70 * 1000);

// then: job should be created
Assert.assertEquals(1, flowCrontabService.triggers().size());
Job job = jobService.find(flow.getPath(), 1);
Assert.assertEquals(JobCategory.SCHEDULER, job.getCategory());
Assert.assertEquals("master", job.getEnv(FlowEnvs.FLOW_TASK_CRONTAB_BRANCH));
Assert.assertEquals("0/10 * * * * ?", job.getEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT));
Assert.assertEquals("0/1 * * * ?", job.getEnv(FlowEnvs.FLOW_TASK_CRONTAB_CONTENT));

// when: delete env variable of crontab
Set<String> varToDel = Sets.newHashSet(
Expand Down