Skip to content

Commit

Permalink
Sort by ID instead of task_finished. Add customizable limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
geirsagberg committed Jul 13, 2024
1 parent 8508368 commit 2aece06
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 156 deletions.
59 changes: 35 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# DB Scheduler UI

![build status](https://github.com/bekk/db-scheduler-ui/workflows/Build/badge.svg)
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)


A UI extension for [db-scheduler](https://github.com/kagkarlsson/db-scheduler) that provides a browser accessible
A UI extension for [db-scheduler](https://github.com/kagkarlsson/db-scheduler) that provides a browser accessible
dashboard for monitoring and basic administration of tasks.


## Features

* **View tasks** that are Scheduled, Running or Failed.
Expand All @@ -33,79 +32,91 @@ dashboard for monitoring and basic administration of tasks.
* Minimum Java 11 and SpringBoot 2.7
* Optional (if you want task history): db-scheduler-log version 0.7.0


## Getting started

1. Add the db-scheduler-ui spring boot starter maven dependency

```xml

<dependency>
<groupId>no.bekk.db-scheduler-ui</groupId>
<artifactId>db-scheduler-ui-starter</artifactId>
<version>1.0.1</version>
</dependency>
```

2. Read the [db-scheduler](https://github.com/kagkarlsson/db-scheduler) readme and follow the getting started guide. The most important is to create the `scheduled_tasks` table correctly.
2. Read the [db-scheduler](https://github.com/kagkarlsson/db-scheduler) readme and follow the getting started guide. The
most important is to create the `scheduled_tasks` table correctly.
You do not need to add db-scheduler as a dependency.
3. Start your application. The db-scheduler UI can be reached at `<your-app-url>/db-scheduler`


## Optional: task history

If you want to add task history to your UI you need to add the following dependency:

```xml

<dependency>
<groupId>io.rocketbase.extension</groupId>
<artifactId>db-scheduler-log-spring-boot-starter</artifactId>
<version>0.7.0</version>
</dependency>
```
Follow the [readme](https://github.com/rocketbase-io/db-scheduler-log) to create the correct database table.

You also need to set `db-scheduler-ui.history=true` in your application.properties file.
Follow the [readme](https://github.com/rocketbase-io/db-scheduler-log) to create the correct database table.

You also need to set `db-scheduler-ui.history=true` in your application.properties file, and consider setting a limit to
the number of logs fetched: `db-scheduler-ui.log-limit=1000`.

## How it works
db-scheduler-ui adds a REST-api package that has a bundled frontend application.

db-scheduler-ui adds a REST-api package that has a bundled frontend application.
Springboot is used to configure beans and handle dependencies within the library and your application.
The user interface makes calls to the scheduler-client, where it can fetch, delete, run, and reschedule tasks.
These tasks are then shown in the web application.
An optional log module can also be added, making it possible to view the history of all your task executions.
The user interface makes calls to the scheduler-client, where it can fetch, delete, run, and reschedule tasks.
These tasks are then shown in the web application.
An optional log module can also be added, making it possible to view the history of all your task executions.

## Configuration

db-scheduler-ui can be configured using the following options: <br>
db-scheduler-ui can be configured using the following options:

Turns on db-scheduler-log, default value is false. See [Optional: task history](#optional-task-history)
```
db-scheduler-ui.history=false
```
<br>
If you for some reason want to hide the task data you can set this to false. defaults to true
`history`: Turns on db-scheduler-log, default value is `false`. You can also limit the number of logs to fetch
with `log-limit`.

```
db-scheduler-ui.task-data=true
db-scheduler-ui.history=true
db-scheduler-ui.log-limit=1000
```

If you for some reason want to hide the task data you can set this to false. defaults to `true`

```
db-scheduler-ui.task-data=false
```

## Contributing

Feel free to create pull requests if there are features or improvements you want to add.
PR's need to be approved by one of the maintainers. To publish a new version, create a release in Github and tag it with a SemVer version.
Feel free to create pull requests if there are features or improvements you want to add.
PR's need to be approved by one of the maintainers. To publish a new version, create a release in Github and tag it with
a SemVer version.
A new release will then be released to maven central by a github action using JReleaser.

Before submitting a PR make sure to run `mvn spotless:apply` to format the code correctly.
Please use the prettier config when making frontend changes


## Local development

Prerequisites:

* Maven
* JDK11
* Node
* npm

There are two ways to run the frontend locally.

1. running `npm run dev` inside the db-scheduler-ui-frontend folder
2. running `mvn install` will build the frontend and copy the output to the resources folder in the `db-scheduler-ui` module. The frontend will then be available at the same port as the example app.
2. running `mvn install` will build the frontend and copy the output to the resources folder in the `db-scheduler-ui`
module. The frontend will then be available at the same port as the example app.

To run the backend run `mvn clean install` and then run the example app.
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ LogLogic logLogic(
Caching caching,
DbSchedulerCustomizer customizer,
DbSchedulerUiProperties properties,
@Value("${db-scheduler-log.table-name:scheduled_execution_logs}") String logTableName) {
@Value("${db-scheduler-log.table-name:scheduled_execution_logs}") String logTableName,
@Value("${db-scheduler-ui.log-limit:0}") int logLimit) {
return new LogLogic(
dataSource,
customizer.serializer().orElse(Serializer.DEFAULT_JAVA_SERIALIZER),
caching,
properties.isTaskData(),
logTableName);
logTableName,
logLimit);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
@Getter
@ConfigurationProperties("db-scheduler-ui")
public class DbSchedulerUiProperties {

private boolean enabled = true;
private boolean taskData = true;
private boolean history = false;
private int logLimit = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import lombok.Getter;

@Getter
public class GetLogsResponse {

private final int numberOfItems;
private final int numberOfPages;
private final List<LogModel> items;
Expand All @@ -31,16 +34,4 @@ public GetLogsResponse(
this.numberOfPages = totalLogs == 0 ? 0 : (int) Math.ceil((double) totalLogs / pageSize);
this.items = pagedLogs;
}

public int getNumberOfItems() {
return numberOfItems;
}

public int getNumberOfPages() {
return numberOfPages;
}

public List<LogModel> getItems() {
return items;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import lombok.Getter;

@Getter
public class GetTasksResponse {

private final int numberOfItems;
private final int numberOfPages;
private final List<TaskModel> items;
Expand All @@ -31,16 +34,4 @@ public GetTasksResponse(
this.numberOfPages = totalTasks == 0 ? 0 : (int) Math.ceil((double) totalTasks / pageSize);
this.items = pagedTasks;
}

public int getNumberOfItems() {
return numberOfItems;
}

public int getNumberOfPages() {
return numberOfPages;
}

public List<TaskModel> getItems() {
return items;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@
*/
package no.bekk.dbscheduler.ui.model;

import lombok.Getter;

@Getter
public class LogPollResponse {
public LogPollResponse(int newFailures, int newSucceeded) {
this.newFailures = newFailures;
this.newSucceeded = newSucceeded;
}

private final int newFailures;
private final int newSucceeded;

public int getNewFailures() {
return newFailures;
}

public int getNewSucceeded() {
return newSucceeded;
public LogPollResponse(int newFailures, int newSucceeded) {
this.newFailures = newFailures;
this.newSucceeded = newSucceeded;
}

private final int newSucceeded;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
*/
package no.bekk.dbscheduler.ui.model;

import lombok.Getter;

@Getter
public class PollResponse {

private final int newFailures;
private final int newRunning;
private final int newTasks;
Expand All @@ -28,24 +32,4 @@ public PollResponse(
this.stoppedFailing = stoppedFailing;
this.finishedRunning = finishedRunning;
}

public int getNewFailures() {
return newFailures;
}

public int getNewRunning() {
return newRunning;
}

public int getNewTasks() {
return newTasks;
}

public int getStoppedFailing() {
return stoppedFailing;
}

public int getFinishedRunning() {
return finishedRunning;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
package no.bekk.dbscheduler.ui.model;

import java.time.Instant;
import lombok.Getter;

@Getter
public class TaskDetailsRequestParams extends TaskRequestParams {

private final String taskId;
Expand Down Expand Up @@ -51,12 +53,4 @@ public TaskDetailsRequestParams(
this.taskId = taskId;
this.taskName = taskName;
}

public String getTaskId() {
return taskId;
}

public String getTaskName() {
return taskName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@
package no.bekk.dbscheduler.ui.model;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import lombok.Getter;

@Getter
public class TaskRequestParams {

private final TaskFilter filter;
private final int pageNumber;
private final int size;
private final TaskSort sorting;
private final boolean asc;
private boolean refresh;
private final String searchTermTaskName;

private final String searchTermTaskInstance;

private final boolean taskNameExactMatch;

private final boolean taskInstanceExactMatch;
private final Instant startTime;
private final Instant endTime;
private final boolean refresh;

public TaskRequestParams(
TaskFilter filter,
Expand All @@ -56,63 +54,11 @@ public TaskRequestParams(
this.searchTermTaskInstance = searchTermTaskInstance;
this.taskNameExactMatch = taskNameExactMatch != null ? taskNameExactMatch : false;
this.taskInstanceExactMatch = taskInstanceExactMatch != null ? taskInstanceExactMatch : false;
this.startTime = startTime != null ? startTime : Instant.now().minus(50, ChronoUnit.DAYS);
this.endTime = endTime != null ? endTime : Instant.now().plus(50, ChronoUnit.DAYS);
this.startTime = startTime;
this.endTime = endTime;
this.refresh = refresh != null ? refresh : true;
}

public TaskFilter getFilter() {
return filter;
}

public int getPageNumber() {
return pageNumber;
}

public int getSize() {
return size;
}

public TaskSort getSorting() {
return sorting;
}

public boolean isAsc() {
return asc;
}

public boolean isRefresh() {
return refresh;
}

public String getSearchTermTaskName() {
return searchTermTaskName;
}

public String getSearchTermTaskInstance() {
return searchTermTaskInstance;
}

public boolean isTaskNameExactMatch() {
return taskNameExactMatch;
}

public boolean isTaskInstanceExactMatch() {
return taskInstanceExactMatch;
}

public void setRefresh(boolean refresh) {
this.refresh = refresh;
}

public Instant getStartTime() {
return startTime;
}

public Instant getEndTime() {
return endTime;
}

public enum TaskFilter {
ALL,
FAILED,
Expand Down
Loading

0 comments on commit 2aece06

Please sign in to comment.