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
3 changes: 3 additions & 0 deletions src/main/java/org/codelibs/fess/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ private Constants() {
/** Scheduled job identifier. */
public static final String SCHEDULED_JOB = "scheduledJob";

/** Job log ID parameter key for passing pre-generated ID to job execution. */
public static final String JOB_LOG_ID = "jobLogId";

/** Default job target value (all configurations). */
public static final String DEFAULT_JOB_TARGET = "all";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ protected void process(final LaJobRuntime runtime) {
}

final JobLog jobLog = new JobLog(scheduledJob);
final String jobLogId = (String) runtime.getParameterMap().get(Constants.JOB_LOG_ID);
if (jobLogId != null) {
jobLog.setId(jobLogId);
}
final String scriptType = scheduledJob.getScriptType();
final String script = scheduledJob.getScriptData();

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/codelibs/fess/app/web/api/ApiResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,36 @@ public ApiResult result() {
}
}

/**
* Represents an API response for a start job operation.
*/
public static class ApiStartJobResponse extends ApiResponse {
/** The pre-generated job log ID. Null when job logging is disabled. */
protected String jobLogId;

/**
* Default constructor for ApiStartJobResponse.
*/
public ApiStartJobResponse() {
super();
}

/**
* Sets the job log ID.
* @param jobLogId The job log ID to set. Null when job logging is disabled.
* @return This ApiStartJobResponse instance.
*/
public ApiStartJobResponse jobLogId(final String jobLogId) {
this.jobLogId = jobLogId;
return this;
}

@Override
public ApiResult result() {
return new ApiResult(this);
}
}

/**
* Represents an API response for a delete operation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static org.codelibs.fess.app.web.admin.scheduler.AdminSchedulerAction.getScheduledJob;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -75,21 +77,29 @@ public HtmlResponse index() {

/**
* Starts a scheduled job by ID.
* When job logging is enabled, a pre-generated job log ID is returned in the response
* as {@code jobLogId}. When job logging is disabled, {@code jobLogId} is {@code null}.
*
* @param id the ID of the scheduled job to start
* @return JSON response indicating success or failure
* @return JSON response with {@code jobLogId} (nullable) and status
*/
// PUT /api/admin/scheduler/{id}/start
@Execute(urlPattern = "{}/@word")
public JsonResponse<ApiResult> put$start(final String id) {
final String[] jobLogId = { null };
scheduledJobService.getScheduledJob(id).ifPresent(entity -> {
if (!entity.isEnabled() || entity.isRunning()) {
throwValidationErrorApi(messages -> {
messages.addErrorsFailedToStartJob(GLOBAL, entity.getName());
});
}
try {
entity.start();
if (entity.isLoggingEnabled()) {
jobLogId[0] = UUID.randomUUID().toString().replace("-", "");
entity.start(Map.of(Constants.JOB_LOG_ID, jobLogId[0]));
} else {
entity.start();
}
} catch (final Exception e) {
throwValidationErrorApi(messages -> {
messages.addErrorsFailedToStartJob(GLOBAL, entity.getName());
Expand All @@ -100,7 +110,7 @@ public HtmlResponse index() {
messages.addErrorsFailedToStartJob(GLOBAL, id);
});
});
return asJson(new ApiResponse().status(Status.OK).result());
return asJson(new ApiResult.ApiStartJobResponse().jobLogId(jobLogId[0]).status(Status.OK).result());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.codelibs.fess.opensearch.config.exentity;

import java.util.Map;

import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.exception.JobNotFoundException;
Expand Down Expand Up @@ -63,6 +65,20 @@ public void start() {
});
}

public void start(final Map<String, Object> params) {
ComponentUtil.getJobManager().findJobByUniqueOf(LaJobUnique.of(getId())).ifPresent(job -> {
if (params != null && !params.isEmpty()) {
job.launchNow(op -> {
params.forEach(op::param);
});
} else {
job.launchNow();
}
}).orElse(() -> {
throw new JobNotFoundException(this);
});
}

public void stop() {
ComponentUtil.getJobManager().findJobByUniqueOf(LaJobUnique.of(getId())).ifPresent(job -> {
job.stopNow();
Expand Down
Loading
Loading