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

Provides some groundwork for script based import customizations. #1959

Merged
merged 6 commits into from
Apr 2, 2024
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
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/process/ProcessContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public interface ProcessContext extends TaskContextAdapter {
TableOutput.ColumnBuilder addTable(String name, String label);

/**
* Adds an additional log output to the process.
* Adds a log output to the process.
* <p>
* Use {@link ProcessLog#into(String)} to add log entries to this output.
*
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/sirius/biz/process/Processes.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ public String createProcess(@Nullable String type,
return process.getIdAsString();
}

/**
* Fetches the currently active process.
*
* @return the process for which the current thread is executing or an empty optional if no process is active
*/
public Optional<Supplier<Process>> fetchCurrentProcess() {
TaskContextAdapter adapter = TaskContext.get().getAdapter();
if (adapter instanceof ProcessEnvironment processEnvironment) {
return Optional.of(() -> fetchRequiredProcess(processEnvironment.getProcessId()));
sabieber marked this conversation as resolved.
Show resolved Hide resolved
} else {
return Optional.empty();
}
}

/**
* Creates a new process for the currently active user.
*
Expand Down Expand Up @@ -1086,7 +1100,7 @@ public Optional<ProcessLog> fetchProcessLogForUser(String processLogId) {
*
* @param processLog the log entry to modify
* @param newState the new state to set
* @param webContext the request to respond to
* @param webContext the request to respond to
* @param returnUrl the URL to redirect the request to once the modification has been performed and is visible
*/
public void updateProcessLogStateAndReturn(ProcessLog processLog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.ide;
package sirius.biz.scripting;

import sirius.kernel.async.TaskContextAdapter;
import sirius.kernel.commons.RateLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.ide;
package sirius.biz.scripting;

import sirius.kernel.async.TaskContext;
import sirius.kernel.di.std.Register;
Expand All @@ -15,6 +15,7 @@
import sirius.pasta.noodle.compiler.CompilationContext;
import sirius.pasta.noodle.compiler.ir.Node;
import sirius.pasta.noodle.macros.BasicMacro;
import sirius.pasta.noodle.sandbox.NoodleSandbox;

import javax.annotation.Nonnull;
import java.util.List;
Expand All @@ -23,6 +24,7 @@
* Provides a shortcut to invoke {@link TaskContext#log(String, Object...)}.
*/
@Register
@NoodleSandbox(NoodleSandbox.Accessibility.GRANTED)
public class LogMacro extends BasicMacro {
@Override
protected Class<?> getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.ide;
package sirius.biz.scripting;

import com.fasterxml.jackson.databind.node.ObjectNode;
import sirius.biz.cluster.Interconnect;
Expand All @@ -24,7 +24,6 @@
import sirius.kernel.health.Exceptions;
import sirius.kernel.health.HandledException;
import sirius.kernel.health.Log;
import sirius.pasta.Pasta;
import sirius.pasta.noodle.Callable;
import sirius.pasta.noodle.ScriptingException;
import sirius.pasta.noodle.SimpleEnvironment;
Expand Down Expand Up @@ -54,6 +53,11 @@
@Register(classes = {Scripting.class, InterconnectHandler.class})
public class Scripting implements InterconnectHandler {

/**
* Contains a global logger to use for errors or messages related to custom scripts.
*/
public static final Log LOG = Log.get("scripting");

private static final int MAX_MESSAGES = 256;

private static final String TASK_TYPE = "type";
Expand Down Expand Up @@ -237,7 +241,7 @@ private void handleTaskForNode(ObjectNode event, String jobNumber) {
} catch (CompileException | ScriptingException | HandledException exception) {
logInTranscript(jobNumber, exception.getMessage());
} catch (Exception exception) {
logInTranscript(jobNumber, Exceptions.handle(Pasta.LOG, exception).getMessage());
logInTranscript(jobNumber, Exceptions.handle(LOG, exception).getMessage());
}

logInTranscript(jobNumber, Strings.apply("Execution completed (%s)", watch.duration()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.ide;
package sirius.biz.scripting;

import sirius.biz.web.BizController;
import sirius.kernel.commons.Strings;
Expand Down Expand Up @@ -77,7 +77,7 @@ public void scripting(WebContext webContext) {
nodes.addFirst(Tuple.create("Current Machine", Scripting.LOCAL_NODE));
nodes.add(Tuple.create("All Machines", Scripting.ALL_NODES));

webContext.respondWith().template("/templates/biz/ide/scripting.html.pasta", nodes);
webContext.respondWith().template("/templates/biz/scripting/scripting.html.pasta", nodes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* http://www.scireum.de - info@scireum.de
*/

package sirius.biz.ide;
package sirius.biz.scripting;

/**
* Wraps a transcript message which can be created by a running script and is available on all nodes.
*/
class TranscriptMessage {
public class TranscriptMessage {

private final String node;
private final String jobNumber;
Expand Down
Loading