@budibase/server 2.6.19-alpha.31 → 2.6.19-alpha.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/query.js CHANGED
@@ -5898,14 +5898,15 @@ init_src();
5898
5898
  // ../backend-core/src/redis/redlockImpl.ts
5899
5899
  var redlockImpl_exports = {};
5900
5900
  __export(redlockImpl_exports, {
5901
- doWithLock: () => doWithLock
5901
+ doWithLock: () => doWithLock,
5902
+ newRedlock: () => newRedlock
5902
5903
  });
5903
5904
  var import_redlock = __toESM(require("redlock"));
5904
5905
  init_init();
5905
5906
  init_src();
5906
5907
  init_context2();
5907
5908
  init_environment2();
5908
- var getClient = async (type, opts) => {
5909
+ async function getClient(type, opts) {
5909
5910
  if (type === "custom" /* CUSTOM */) {
5910
5911
  return newRedlock(opts);
5911
5912
  }
@@ -5916,6 +5917,9 @@ var getClient = async (type, opts) => {
5916
5917
  case "try_once" /* TRY_ONCE */: {
5917
5918
  return newRedlock(OPTIONS.TRY_ONCE);
5918
5919
  }
5920
+ case "try_twice" /* TRY_TWICE */: {
5921
+ return newRedlock(OPTIONS.TRY_TWICE);
5922
+ }
5919
5923
  case "default" /* DEFAULT */: {
5920
5924
  return newRedlock(OPTIONS.DEFAULT);
5921
5925
  }
@@ -5926,12 +5930,15 @@ var getClient = async (type, opts) => {
5926
5930
  throw new Error(`Could not get redlock client: ${type}`);
5927
5931
  }
5928
5932
  }
5929
- };
5933
+ }
5930
5934
  var OPTIONS = {
5931
5935
  TRY_ONCE: {
5932
5936
  // immediately throws an error if the lock is already held
5933
5937
  retryCount: 0
5934
5938
  },
5939
+ TRY_TWICE: {
5940
+ retryCount: 1
5941
+ },
5935
5942
  TEST: {
5936
5943
  // higher retry count in unit tests
5937
5944
  // due to high contention.
@@ -5958,21 +5965,25 @@ var OPTIONS = {
5958
5965
  retryDelay: 500
5959
5966
  }
5960
5967
  };
5961
- var newRedlock = async (opts = {}) => {
5968
+ async function newRedlock(opts = {}) {
5962
5969
  let options2 = { ...OPTIONS.DEFAULT, ...opts };
5963
5970
  const redisWrapper = await getLockClient();
5964
5971
  const client3 = redisWrapper.getClient();
5965
5972
  return new import_redlock.default([client3], options2);
5966
- };
5967
- var doWithLock = async (opts, task) => {
5973
+ }
5974
+ function getLockName(opts) {
5975
+ const prefix = opts.systemLock ? "system" : getTenantId();
5976
+ let name = `lock:${prefix}_${opts.name}`;
5977
+ if (opts.resource) {
5978
+ name = name + `_${opts.resource}`;
5979
+ }
5980
+ return name;
5981
+ }
5982
+ async function doWithLock(opts, task) {
5968
5983
  const redlock = await getClient(opts.type, opts.customOptions);
5969
5984
  let lock;
5970
5985
  try {
5971
- const prefix = opts.systemLock ? "system" : getTenantId();
5972
- let name = `lock:${prefix}_${opts.name}`;
5973
- if (opts.resource) {
5974
- name = name + `_${opts.resource}`;
5975
- }
5986
+ const name = getLockName(opts);
5976
5987
  lock = await redlock.lock(name, opts.ttl);
5977
5988
  const result = await task();
5978
5989
  return { executed: true, result };
@@ -5980,7 +5991,6 @@ var doWithLock = async (opts, task) => {
5980
5991
  console.warn("lock error");
5981
5992
  if (e.name === "LockError") {
5982
5993
  if (opts.type === "try_once" /* TRY_ONCE */) {
5983
- console.warn(e);
5984
5994
  return { executed: false };
5985
5995
  } else {
5986
5996
  console.error(e);
@@ -5995,7 +6005,7 @@ var doWithLock = async (opts, task) => {
5995
6005
  await lock.unlock();
5996
6006
  }
5997
6007
  }
5998
- };
6008
+ }
5999
6009
 
6000
6010
  // ../backend-core/src/platform/tenants.ts
6001
6011
  var TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants;