Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GOBBLIN-1875] Create Unique Trigger Keys #3737

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -586,9 +587,13 @@ public void close() throws IOException {
* Get a {@link org.quartz.Trigger} from the given job configuration properties.
*/
public static Trigger createTriggerForJob(JobKey jobKey, Properties jobProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you verify that this method is not called anywhere else? Asking because this is a backward incompatible change. You can leave this method and make it by default a call to createTriggerForJob(jobKey, jobProps, Optional.absent())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I checked everywhere and added. It would not compile otherwise also.

// Build a trigger for the job with the given cron-style schedule
Random random = new Random();
/*
Build a trigger for the job with the given cron-style schedule
Append a random integer to job name to be able to add multiple triggers associated with the same job.
umustafi marked this conversation as resolved.
Show resolved Hide resolved
*/
return TriggerBuilder.newTrigger()
.withIdentity(jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY),
.withIdentity(jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY) + random.nextInt(1000),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random number will make it super hard to debug if something went wrong.. does it make sense to change the trigger name to be normal flow name -> normal trigger that tigger the execution; {flowName + “reminder job” + executionid/timestamp} -> reminder job for a specific execution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated with this!

Strings.nullToEmpty(jobProps.getProperty(ConfigurationKeys.JOB_GROUP_KEY)))
.forJob(jobKey)
.withSchedule(CronScheduleBuilder.cronSchedule(jobProps.getProperty(ConfigurationKeys.JOB_SCHEDULE_KEY)))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.gobblin.scheduler;

import java.util.Properties;
import org.apache.gobblin.configuration.ConfigurationKeys;
import org.junit.Assert;
import org.quartz.JobKey;
import org.quartz.Trigger;
import org.testng.annotations.Test;


public class JobSchedulerTest {
// This test creates two triggers with the same job key and job props, then verifies the trigger keys are unique
@Test
public void testCreateUniqueTriggersForJob() {
String jobName = "flow123";
String jobGroup = "groupA";
JobKey jobKey = new JobKey(jobName, jobGroup);
Properties jobProps = new Properties();
jobProps.put(ConfigurationKeys.JOB_NAME_KEY, jobName);
jobProps.put(ConfigurationKeys.JOB_GROUP_KEY, jobGroup);
jobProps.put(ConfigurationKeys.JOB_SCHEDULE_KEY, "0/2 * * * * ?");

Trigger trigger1 = JobScheduler.createTriggerForJob(jobKey, jobProps);
Trigger trigger2 = JobScheduler.createTriggerForJob(jobKey, jobProps);

Assert.assertTrue(trigger1.getKey() != trigger2.getKey());
}
}