Skip to content

Commit

Permalink
CB-3508 update async web task event logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yagudin10 committed Dec 9, 2024
1 parent f2e3406 commit 51ebebb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,41 @@
*/
package io.cloudbeaver.model;

import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.runtime.AbstractJob;

/**
* Web connection info
* Web async task info
*/
public class WebAsyncTaskInfo {

private String id;
private String name;
private boolean running;
@NotNull
private final String id;
@NotNull
private final String name;
private boolean running = false;
private Object result;
private Object extendedResult;
private String status;
private Throwable jobError;

private AbstractJob job;

public WebAsyncTaskInfo(String id, String name) {
public WebAsyncTaskInfo(@NotNull String id, @NotNull String name) {
this.id = id;
this.name = name;
}

@NotNull
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@NotNull
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isRunning() {
return running;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import io.cloudbeaver.model.session.monitor.TaskProgressMonitor;
import io.cloudbeaver.model.session.monitor.TaskWithEventsProgressMonitor;
import io.cloudbeaver.model.user.WebUser;
import io.cloudbeaver.service.DBWSessionHandler;
import io.cloudbeaver.service.sql.WebSQLConstants;
Expand Down Expand Up @@ -66,6 +65,7 @@
import org.jkiss.dbeaver.model.websocket.event.MessageType;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.WSSessionLogUpdatedEvent;
import org.jkiss.dbeaver.model.websocket.event.session.WSSessionTaskInfoEvent;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.utils.CommonUtils;

Expand Down Expand Up @@ -508,7 +508,7 @@ public DBRProgressMonitor getProgressMonitor() {
///////////////////////////////////////////////////////
// Async model

public WebAsyncTaskInfo getAsyncTask(String taskId, String taskName, boolean create) {
public WebAsyncTaskInfo getAsyncTask(@NotNull String taskId, @NotNull String taskName, boolean create) {

Check warning on line 511 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java:511:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
synchronized (asyncTasks) {
WebAsyncTaskInfo taskInfo = asyncTasks.get(taskId);
if (taskInfo == null && create) {
Expand All @@ -525,7 +525,6 @@ public WebAsyncTaskInfo asyncTaskStatus(String taskId, boolean removeOnFinish) t
if (taskInfo == null) {
throw new DBWebException("Task '" + taskId + "' not found");
}
taskInfo.setRunning(taskInfo.getJob() != null && !taskInfo.getJob().isFinished());
if (removeOnFinish && !taskInfo.isRunning()) {
asyncTasks.remove(taskId);
}
Expand All @@ -548,11 +547,7 @@ public boolean asyncTaskCancel(String taskId) throws DBWebException {
return true;
}

public WebAsyncTaskInfo createAndRunAsyncTask(String taskName, WebAsyncTaskProcessor<?> runnable) {
return createAndRunAsyncTask(taskName, runnable, false);
}

public WebAsyncTaskInfo createAndRunAsyncTask(String taskName, WebAsyncTaskProcessor<?> runnable, boolean sendEvent) {
public WebAsyncTaskInfo createAndRunAsyncTask(@NotNull String taskName, @NotNull WebAsyncTaskProcessor<?> runnable) {

Check warning on line 550 in server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java:550:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
int taskId = TASK_ID.incrementAndGet();
WebAsyncTaskInfo asyncTask = getAsyncTask(String.valueOf(taskId), taskName, true);

Expand All @@ -561,9 +556,7 @@ public WebAsyncTaskInfo createAndRunAsyncTask(String taskName, WebAsyncTaskProce
protected IStatus run(DBRProgressMonitor monitor) {
int curTaskCount = taskCount.incrementAndGet();

DBRProgressMonitor taskMonitor = sendEvent ?
new TaskWithEventsProgressMonitor(monitor, WebSession.this, asyncTask) :
new TaskProgressMonitor(monitor, asyncTask);
DBRProgressMonitor taskMonitor = new TaskProgressMonitor(monitor, WebSession.this, asyncTask);

try {
Number queryLimit = application.getAppConfiguration().getResourceQuota(WebSQLConstants.QUOTA_PROP_QUERY_LIMIT);
Expand All @@ -576,14 +569,15 @@ protected IStatus run(DBRProgressMonitor monitor) {
asyncTask.setResult(runnable.getResult());
asyncTask.setExtendedResult(runnable.getExtendedResults());
asyncTask.setStatus("Finished");
asyncTask.setRunning(false);
} catch (InvocationTargetException e) {
addSessionError(e.getTargetException());
asyncTask.setJobError(e.getTargetException());
} catch (Exception e) {
asyncTask.setJobError(e);
} finally {
taskCount.decrementAndGet();
asyncTask.setRunning(false);
addSessionEvent(WSSessionTaskInfoEvent.finish(asyncTask.getId()));
}
return Status.OK_STATUS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package io.cloudbeaver.model.session.monitor;

import io.cloudbeaver.model.WebAsyncTaskInfo;
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.ProxyProgressMonitor;
import org.jkiss.dbeaver.model.websocket.event.session.WSSessionTaskInfoEvent;

/**
* Task progress monitor.
Expand All @@ -29,21 +31,25 @@ public class TaskProgressMonitor extends ProxyProgressMonitor {

@NotNull
private final WebAsyncTaskInfo asyncTask;
private final WebSession webSession;

public TaskProgressMonitor(DBRProgressMonitor original, @NotNull WebAsyncTaskInfo asyncTask) {
public TaskProgressMonitor(DBRProgressMonitor original, @NotNull WebSession webSession, @NotNull WebAsyncTaskInfo asyncTask) {
super(original);
this.webSession = webSession;
this.asyncTask = asyncTask;
}

@Override
public void beginTask(String name, int totalWork) {
super.beginTask(name, totalWork);
asyncTask.setStatus(name);
webSession.addSessionEvent(WSSessionTaskInfoEvent.update(asyncTask.getId(), name));
}

@Override
public void subTask(String name) {
super.subTask(name);
asyncTask.setStatus(name);
webSession.addSessionEvent(WSSessionTaskInfoEvent.update(asyncTask.getId(), name));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ enum CBServerEventId {
cb_object_permissions_updated,
cb_subject_permissions_updated,

cb_database_output_log_updated
cb_database_output_log_updated,

cb_session_task_info_updated, @since(version: "24.3.1")
cb_session_task_info_finished @since(version: "24.3.1")
}

# Events sent by client
Expand All @@ -53,7 +56,8 @@ enum CBEventTopic {
cb_object_permissions,
cb_subject_permissions,
cb_database_output_log,
cb_delete_temp_folder
cb_delete_temp_folder,
cb_session_task @since(version: "24.3.1")
}

# Base server event interface
Expand Down Expand Up @@ -178,6 +182,13 @@ type WSOutputLogInfo {
# Add more fields as needed
}

# Async task info status event
type WSAsyncTaskInfo @since(version: "24.3.1") {
id: CBServerEventId!
taskId: ID!
statusName: String
}

extend type Query {
emptyEvent: Boolean
}
Expand Down

0 comments on commit 51ebebb

Please sign in to comment.