Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release' into chore/controller-l…
Browse files Browse the repository at this point in the history
…ayer
  • Loading branch information
sondermanish committed Jan 2, 2025
2 parents d18f3cd + 51f3d0e commit 3959aab
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 111 deletions.
20 changes: 14 additions & 6 deletions app/client/src/ce/utils/actionExecutionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getCurrentEnvironmentDetails } from "ee/selectors/environmentSelectors"
import type { Plugin } from "api/PluginApi";
import { get, isNil } from "lodash";
import type { JSCollectionData } from "ee/reducers/entityReducers/jsActionsReducer";
import { objectKeys } from "@appsmith/utils";

export function getPluginActionNameToDisplay(action: Action) {
return action.name;
Expand All @@ -20,7 +21,7 @@ export const getActionProperties = (
) => {
const actionProperties: Record<string, unknown> = {};

Object.keys(keyConfig).forEach((key) => {
objectKeys(keyConfig).forEach((key) => {
const value = get(action, key);

if (!isNil(value)) {
Expand Down Expand Up @@ -69,7 +70,7 @@ export function getActionExecutionAnalytics(
datasourceId: datasourceId,
isMock: !!datasource?.isMock,
actionId: action?.id,
inputParams: Object.keys(params).length,
inputParams: objectKeys(params).length,
source: ActionExecutionContext.EVALUATION_ACTION_TRIGGER, // Used in analytic events to understand who triggered action execution
};

Expand Down Expand Up @@ -98,17 +99,24 @@ export function isBrowserExecutionAllowed(..._args: any[]) {
return true;
}

// Function to extract the test payload from the collection data
/**
* Function to extract the test payload from the collection data
* @param [collectionData] from the js Object
* @param [defaultValue=""] to be returned if no information is found,
* returns an empty string by default
* @returns stored value from the collectionData
* */
export const getTestPayloadFromCollectionData = (
collectionData: JSCollectionData | undefined,
defaultValue = "",
): string => {
if (!collectionData) return "";
if (!collectionData) return defaultValue;

const activeJSActionId = collectionData?.activeJSActionId;
const testPayload: Record<string, unknown> | undefined = collectionData?.data
?.testPayload as Record<string, unknown>;

if (!activeJSActionId || !testPayload) return "";
if (!activeJSActionId || !testPayload) return defaultValue;

return (testPayload[activeJSActionId] as string) || "";
return testPayload[activeJSActionId] as string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
public enum ArtifactType {
APPLICATION,
PACKAGE,
WORKFLOW
WORKFLOW;

public String lowerCaseName() {
return this.name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.appsmith.server.git;

import com.appsmith.external.git.constants.GitSpan;
import com.appsmith.server.constants.ArtifactType;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.helpers.RedisUtils;
Expand All @@ -26,17 +27,18 @@ public class GitRedisUtils {
/**
* Adds a baseArtifact id as a key in redis, the presence of this key represents a symbolic lock, essentially meaning that no new operations
* should be performed till this key remains present.
* @param baseArtifactId : base id of the artifact for which the key is getting added.
* @param commandName : Name of the operation which is trying to acquire the lock, this value will be added against the key
*
* @param key : base id of the artifact for which the key is getting added.
* @param commandName : Name of the operation which is trying to acquire the lock, this value will be added against the key
* @param isRetryAllowed : Boolean for whether retries for adding the value is allowed
* @return a boolean publisher for the added file locks
*/
public Mono<Boolean> addFileLock(String baseArtifactId, String commandName, Boolean isRetryAllowed) {
public Mono<Boolean> addFileLock(String key, String commandName, Boolean isRetryAllowed) {
long numberOfRetries = Boolean.TRUE.equals(isRetryAllowed) ? MAX_RETRIES : 0L;

log.info("Git command {} is trying to acquire the lock for application id {}", commandName, baseArtifactId);
log.info("Git command {} is trying to acquire the lock for identity {}", commandName, key);
return redisUtils
.addFileLock(baseArtifactId, commandName)
.addFileLock(key, commandName)
.retryWhen(Retry.fixedDelay(numberOfRetries, RETRY_DELAY)
.onRetryExhaustedThrow((retryBackoffSpec, retrySignal) -> {
if (retrySignal.failure() instanceof AppsmithException) {
Expand All @@ -49,13 +51,16 @@ public Mono<Boolean> addFileLock(String baseArtifactId, String commandName, Bool
.tap(Micrometer.observation(observationRegistry));
}

public Mono<Boolean> addFileLock(String defaultApplicationId, String commandName) {
return addFileLock(defaultApplicationId, commandName, true);
public Mono<Boolean> addFileLock(String baseArtifactId, String commandName) {
String key = generateRedisKey(ArtifactType.APPLICATION, baseArtifactId);
return addFileLock(key, commandName, true);
}

public Mono<Boolean> releaseFileLock(String defaultApplicationId) {
public Mono<Boolean> releaseFileLock(String baseArtifactId) {
String key = generateRedisKey(ArtifactType.APPLICATION, baseArtifactId);

return redisUtils
.releaseFileLock(defaultApplicationId)
.releaseFileLock(key)
.name(GitSpan.RELEASE_FILE_LOCK)
.tap(Micrometer.observation(observationRegistry));
}
Expand All @@ -64,33 +69,47 @@ public Mono<Boolean> releaseFileLock(String defaultApplicationId) {
* This is a wrapper method for acquiring git lock, since multiple ops are used in sequence
* for a complete composite operation not all ops require to acquire the lock hence a dummy flag is sent back for
* operations in that is getting executed in between
*
* @param artifactType
* @param baseArtifactId : id of the base artifact for which ops would be locked
* @param isLockRequired : is lock really required or is it a proxy function
* @return : Boolean for whether the lock is acquired
*/
// TODO @Manish add artifactType reference in incoming prs.
public Mono<Boolean> acquireGitLock(String baseArtifactId, String commandName, Boolean isLockRequired) {
public Mono<Boolean> acquireGitLock(
ArtifactType artifactType, String baseArtifactId, String commandName, Boolean isLockRequired) {
if (!Boolean.TRUE.equals(isLockRequired)) {
return Mono.just(Boolean.TRUE);
}

return addFileLock(baseArtifactId, commandName);
String key = generateRedisKey(artifactType, baseArtifactId);

return addFileLock(key, commandName, true);
}

/**
* This is a wrapper method for releasing git lock, since multiple ops are used in sequence
* for a complete composite operation not all ops require to acquire the lock hence a dummy flag is sent back for
* operations in that is getting executed in between
*
* @param artifactType
* @param baseArtifactId : id of the base artifact for which ops would be locked
* @param isLockRequired : is lock really required or is it a proxy function
* @return : Boolean for whether the lock is released
*/
// TODO @Manish add artifactType reference in incoming prs
public Mono<Boolean> releaseFileLock(String baseArtifactId, boolean isLockRequired) {
public Mono<Boolean> releaseFileLock(ArtifactType artifactType, String baseArtifactId, boolean isLockRequired) {
if (!Boolean.TRUE.equals(isLockRequired)) {
return Mono.just(Boolean.TRUE);
}

return releaseFileLock(baseArtifactId);
String key = generateRedisKey(artifactType, baseArtifactId);

return redisUtils
.releaseFileLock(key)
.name(GitSpan.RELEASE_FILE_LOCK)
.tap(Micrometer.observation(observationRegistry));
}

private String generateRedisKey(ArtifactType artifactType, String artifactId) {
return artifactType.lowerCaseName() + "-" + artifactId;
}
}
Loading

0 comments on commit 3959aab

Please sign in to comment.