-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from kagkarlsson/scheduler_client_improvements
Scheduler client improvements
- Loading branch information
Showing
15 changed files
with
487 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 79 additions & 55 deletions
134
db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ScheduledExecution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,79 @@ | ||
/** | ||
* Copyright (C) Gustav Karlsson | ||
* | ||
* Licensed 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 com.github.kagkarlsson.scheduler; | ||
import com.github.kagkarlsson.scheduler.task.Execution; | ||
import com.github.kagkarlsson.scheduler.task.TaskInstance; | ||
import com.github.kagkarlsson.scheduler.task.TaskInstanceId; | ||
import java.time.Instant; | ||
import java.util.Objects; | ||
public class ScheduledExecution<DATA_TYPE> { | ||
private final Class<DATA_TYPE> dataClass; | ||
private final Execution execution; | ||
public ScheduledExecution(Class<DATA_TYPE> dataClass, Execution execution) { | ||
this.dataClass = dataClass; | ||
this.execution = execution; | ||
} | ||
public TaskInstanceId getTaskInstance() { | ||
return execution.taskInstance; | ||
} | ||
public Instant getExecutionTime() { | ||
return execution.getExecutionTime(); | ||
} | ||
@SuppressWarnings("unchecked") | ||
public DATA_TYPE getData() { | ||
if (dataClass.isInstance(this.execution.taskInstance.getData())) { | ||
return (DATA_TYPE) this.execution.taskInstance.getData(); | ||
} | ||
throw new DataClassMismatchException(); | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ScheduledExecution<?> that = (ScheduledExecution<?>) o; | ||
return Objects.equals(execution, that.execution); | ||
} | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(execution); | ||
} | ||
public static class DataClassMismatchException extends RuntimeException { | ||
} | ||
} | ||
/** | ||
* Copyright (C) Gustav Karlsson | ||
* | ||
* Licensed 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 com.github.kagkarlsson.scheduler; | ||
import com.github.kagkarlsson.scheduler.task.Execution; | ||
import com.github.kagkarlsson.scheduler.task.TaskInstance; | ||
import com.github.kagkarlsson.scheduler.task.TaskInstanceId; | ||
import java.time.Instant; | ||
import java.util.Objects; | ||
public class ScheduledExecution<DATA_TYPE> { | ||
private final Class<DATA_TYPE> dataClass; | ||
private final Execution execution; | ||
public ScheduledExecution(Class<DATA_TYPE> dataClass, Execution execution) { | ||
this.dataClass = dataClass; | ||
this.execution = execution; | ||
} | ||
|
||
public TaskInstanceId getTaskInstance() { | ||
return execution.taskInstance; | ||
} | ||
|
||
public Instant getExecutionTime() { | ||
return execution.getExecutionTime(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public DATA_TYPE getData() { | ||
if (dataClass.isInstance(this.execution.taskInstance.getData())) { | ||
return (DATA_TYPE) this.execution.taskInstance.getData(); | ||
} | ||
throw new DataClassMismatchException(); | ||
} | ||
|
||
public Instant getLastSuccess() { | ||
return execution.lastSuccess; | ||
} | ||
|
||
public Instant getLastFailure() { | ||
return execution.lastFailure; | ||
} | ||
|
||
public int getConsecutiveFailures() { | ||
return execution.consecutiveFailures; | ||
} | ||
|
||
public boolean isPicked() { | ||
return execution.picked; | ||
} | ||
|
||
public String getPickedBy() { | ||
return execution.pickedBy; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ScheduledExecution<?> that = (ScheduledExecution<?>) o; | ||
return Objects.equals(execution, that.execution); | ||
} | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(execution); | ||
} | ||
public static class DataClassMismatchException extends RuntimeException { | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ScheduledExecutionsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (C) Gustav Karlsson | ||
* | ||
* Licensed 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 com.github.kagkarlsson.scheduler; | ||
|
||
import java.util.Optional; | ||
|
||
public class ScheduledExecutionsFilter { | ||
|
||
private Boolean pickedValue; | ||
|
||
private ScheduledExecutionsFilter() { | ||
} | ||
|
||
public static ScheduledExecutionsFilter all() { | ||
return new ScheduledExecutionsFilter(); | ||
} | ||
|
||
public ScheduledExecutionsFilter withPicked(boolean pickedValue) { | ||
this.pickedValue = pickedValue; | ||
return this; | ||
} | ||
|
||
public Optional<Boolean> getPickedValue() { | ||
return Optional.ofNullable(pickedValue); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.