akeyless-server-commons 1.0.204 → 1.0.206
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/cjs/helpers/postponed_actions.d.ts +113 -0
- package/dist/cjs/helpers/postponed_actions.js +363 -0
- package/dist/cjs/helpers/postponed_actions.js.map +1 -0
- package/dist/cjs/helpers/tasks_helpers.d.ts +2 -1
- package/dist/cjs/helpers/tasks_helpers.js +1 -0
- package/dist/cjs/helpers/tasks_helpers.js.map +1 -1
- package/dist/esm/helpers/postponed_actions.d.ts +113 -0
- package/dist/esm/helpers/postponed_actions.js +359 -0
- package/dist/esm/helpers/postponed_actions.js.map +1 -0
- package/dist/esm/helpers/tasks_helpers.d.ts +2 -1
- package/dist/esm/helpers/tasks_helpers.js +1 -0
- package/dist/esm/helpers/tasks_helpers.js.map +1 -1
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/postponed_actions.js +358 -0
- package/dist/managers/rabbitmq_manager.js +3 -0
- package/dist/types/helpers/index.d.ts +1 -0
- package/dist/types/helpers/postponed_actions.d.ts +113 -0
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { TObject } from "akeyless-types-commons";
|
|
2
|
+
export declare enum PostponedActionStatus {
|
|
3
|
+
pending = "pending",
|
|
4
|
+
processing = "processing",
|
|
5
|
+
completed = "completed",
|
|
6
|
+
cancelled = "cancelled",
|
|
7
|
+
failed = "failed"
|
|
8
|
+
}
|
|
9
|
+
export type PostponedActionTime = Date | string | {
|
|
10
|
+
minutes?: number;
|
|
11
|
+
hours?: number;
|
|
12
|
+
};
|
|
13
|
+
export type JsonPayload = TObject<any>;
|
|
14
|
+
export interface PostponedAction {
|
|
15
|
+
key: string;
|
|
16
|
+
details: JsonPayload;
|
|
17
|
+
action_type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
execute_at: Date;
|
|
20
|
+
status: PostponedActionStatus;
|
|
21
|
+
attempt_count: number;
|
|
22
|
+
created_at: Date;
|
|
23
|
+
updated_at: Date;
|
|
24
|
+
started_at?: Date;
|
|
25
|
+
completed_at?: Date;
|
|
26
|
+
cancelled_at?: Date;
|
|
27
|
+
failed_at?: Date;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AddPostponedAction {
|
|
31
|
+
key: string;
|
|
32
|
+
details: JsonPayload;
|
|
33
|
+
action_type: string;
|
|
34
|
+
description: string;
|
|
35
|
+
execute_at: PostponedActionTime;
|
|
36
|
+
}
|
|
37
|
+
export interface UpdatePostponedAction {
|
|
38
|
+
details?: JsonPayload;
|
|
39
|
+
action_type?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
execute_at?: PostponedActionTime;
|
|
42
|
+
}
|
|
43
|
+
export declare const resolve_postponed_action_time: (value: PostponedActionTime, now?: Date) => Date;
|
|
44
|
+
export declare const get_postponed_action: (key: string) => Promise<PostponedAction | null>;
|
|
45
|
+
export declare const add_postponed_action: (input: AddPostponedAction) => Promise<PostponedAction>;
|
|
46
|
+
export declare const update_postponed_action: (key: string, input: UpdatePostponedAction) => Promise<void>;
|
|
47
|
+
export declare const repostpone_postponed_action: (key: string, execute_at: PostponedActionTime) => Promise<void>;
|
|
48
|
+
export declare const cancel_postponed_action: (key: string) => Promise<void>;
|
|
49
|
+
export declare const complete_postponed_action: (key: string) => Promise<void>;
|
|
50
|
+
export declare const fail_postponed_action: (key: string, error: unknown) => Promise<void>;
|
|
51
|
+
export declare const delete_postponed_action: (key: string) => Promise<void>;
|
|
52
|
+
export declare const claim_postponed_action: (key: string, action_type: string, now?: Date | undefined) => Promise<PostponedAction | null>;
|
|
53
|
+
export declare const claim_due_postponed_actions: (action_type: string, limit?: number | undefined, now?: Date | undefined) => Promise<PostponedAction[]>;
|
|
54
|
+
/**
|
|
55
|
+
* @example Add an action for a specific date and time.
|
|
56
|
+
* ```ts
|
|
57
|
+
* await postponed_actions.add({
|
|
58
|
+
* key: "subscription:123:expire",
|
|
59
|
+
* action_type: "subscription_expiration",
|
|
60
|
+
* description: "Expire subscription 123",
|
|
61
|
+
* details: { subscription_id: "123", notify_customer: true },
|
|
62
|
+
* execute_at: new Date("2026-08-01T12:00:00Z"),
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Add an action relative to the current time. Adding the same key
|
|
67
|
+
* updates the pending action.
|
|
68
|
+
* ```ts
|
|
69
|
+
* await postponed_actions.add({
|
|
70
|
+
* key: "invoice:456:reminder",
|
|
71
|
+
* action_type: "invoice_reminder",
|
|
72
|
+
* description: "Send invoice 456 reminder",
|
|
73
|
+
* details: { invoice_id: "456" },
|
|
74
|
+
* execute_at: { hours: 2, minutes: 30 },
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example Update, repostpone, or cancel a pending action.
|
|
79
|
+
* ```ts
|
|
80
|
+
* await postponed_actions.update("invoice:456:reminder", {
|
|
81
|
+
* description: "Send the final invoice reminder",
|
|
82
|
+
* execute_at: { minutes: 15 },
|
|
83
|
+
* });
|
|
84
|
+
* await postponed_actions.repostpone("invoice:456:reminder", { hours: 1 });
|
|
85
|
+
* await postponed_actions.cancel("invoice:456:reminder");
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Claim and execute due actions. Claiming is atomic, so concurrent
|
|
89
|
+
* workers cannot claim the same action.
|
|
90
|
+
* ```ts
|
|
91
|
+
* const actions = await postponed_actions.claim_due("invoice_reminder", 25);
|
|
92
|
+
* for (const action of actions) {
|
|
93
|
+
* try {
|
|
94
|
+
* await execute_action(action.details);
|
|
95
|
+
* await postponed_actions.complete(action.key);
|
|
96
|
+
* } catch (error) {
|
|
97
|
+
* await postponed_actions.fail(action.key, error);
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare const postponed_actions: {
|
|
103
|
+
get: (key: string) => Promise<PostponedAction | null>;
|
|
104
|
+
add: (input: AddPostponedAction) => Promise<PostponedAction>;
|
|
105
|
+
update: (key: string, input: UpdatePostponedAction) => Promise<void>;
|
|
106
|
+
repostpone: (key: string, execute_at: PostponedActionTime) => Promise<void>;
|
|
107
|
+
cancel: (key: string) => Promise<void>;
|
|
108
|
+
complete: (key: string) => Promise<void>;
|
|
109
|
+
fail: (key: string, error: unknown) => Promise<void>;
|
|
110
|
+
delete: (key: string) => Promise<void>;
|
|
111
|
+
claim: (key: string, action_type: string, now?: Date | undefined) => Promise<PostponedAction | null>;
|
|
112
|
+
claim_due: (action_type: string, limit?: number | undefined, now?: Date | undefined) => Promise<PostponedAction[]>;
|
|
113
|
+
};
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postponed_actions = exports.claim_due_postponed_actions = exports.claim_postponed_action = exports.delete_postponed_action = exports.fail_postponed_action = exports.complete_postponed_action = exports.cancel_postponed_action = exports.repostpone_postponed_action = exports.update_postponed_action = exports.add_postponed_action = exports.get_postponed_action = exports.resolve_postponed_action_time = exports.PostponedActionStatus = void 0;
|
|
4
|
+
const firestore_1 = require("firebase-admin/firestore");
|
|
5
|
+
const firebase_helpers_1 = require("./firebase_helpers");
|
|
6
|
+
const managers_1 = require("../managers");
|
|
7
|
+
const POSTPONED_ACTIONS_COLLECTION = "nx-postponed-actions";
|
|
8
|
+
var PostponedActionStatus;
|
|
9
|
+
(function (PostponedActionStatus) {
|
|
10
|
+
PostponedActionStatus["pending"] = "pending";
|
|
11
|
+
PostponedActionStatus["processing"] = "processing";
|
|
12
|
+
PostponedActionStatus["completed"] = "completed";
|
|
13
|
+
PostponedActionStatus["cancelled"] = "cancelled";
|
|
14
|
+
PostponedActionStatus["failed"] = "failed";
|
|
15
|
+
})(PostponedActionStatus || (exports.PostponedActionStatus = PostponedActionStatus = {}));
|
|
16
|
+
const get_ref = (key) => {
|
|
17
|
+
if (!key.trim()) {
|
|
18
|
+
throw new Error("postponed action key must not be empty");
|
|
19
|
+
}
|
|
20
|
+
if (key.includes("/")) {
|
|
21
|
+
throw new Error("postponed action key must not contain '/'");
|
|
22
|
+
}
|
|
23
|
+
return firebase_helpers_1.db.collection(POSTPONED_ACTIONS_COLLECTION).doc(key);
|
|
24
|
+
};
|
|
25
|
+
const resolve_postponed_action_time = (value, now = new Date()) => {
|
|
26
|
+
if (value instanceof Date || typeof value === "string") {
|
|
27
|
+
const date = value instanceof Date ? new Date(value.getTime()) : new Date(value);
|
|
28
|
+
if (!Number.isFinite(date.getTime())) {
|
|
29
|
+
throw new Error("execute_at must be a valid date");
|
|
30
|
+
}
|
|
31
|
+
return date;
|
|
32
|
+
}
|
|
33
|
+
const { minutes = 0, hours = 0 } = value;
|
|
34
|
+
if (!Number.isFinite(minutes) || !Number.isFinite(hours) || minutes < 0 || hours < 0 || minutes + hours <= 0) {
|
|
35
|
+
throw new Error("relative execute_at must contain positive finite minutes or hours");
|
|
36
|
+
}
|
|
37
|
+
return new Date(now.getTime() + (minutes + hours * 60) * 60_000);
|
|
38
|
+
};
|
|
39
|
+
exports.resolve_postponed_action_time = resolve_postponed_action_time;
|
|
40
|
+
const validate_text = (value, field_name) => {
|
|
41
|
+
if (!value.trim()) {
|
|
42
|
+
throw new Error(`postponed action ${field_name} must not be empty`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const validate_details = (details) => {
|
|
46
|
+
if (!details || Array.isArray(details) || typeof details !== "object") {
|
|
47
|
+
throw new Error("postponed action details must be a JSON object");
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
JSON.stringify(details, (_key, value) => {
|
|
51
|
+
if (value === undefined || typeof value === "bigint" || typeof value === "function" || typeof value === "symbol") {
|
|
52
|
+
throw new Error("unsupported JSON value");
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
55
|
+
throw new Error("JSON numbers must be finite");
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error("postponed action details must be JSON serializable", { cause: error });
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const timestamp_to_date = (value, field_name) => {
|
|
65
|
+
if (value instanceof firestore_1.Timestamp)
|
|
66
|
+
return value.toDate();
|
|
67
|
+
if (value instanceof Date)
|
|
68
|
+
return value;
|
|
69
|
+
throw new Error(`postponed action has invalid ${field_name}`);
|
|
70
|
+
};
|
|
71
|
+
const optional_timestamp_to_date = (value, field_name) => {
|
|
72
|
+
return value === undefined ? undefined : timestamp_to_date(value, field_name);
|
|
73
|
+
};
|
|
74
|
+
const to_postponed_action = (snapshot) => {
|
|
75
|
+
const value = snapshot.data();
|
|
76
|
+
if (!snapshot.exists || !value) {
|
|
77
|
+
throw new Error(`postponed action '${snapshot.id}' does not exist`);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
key: snapshot.id,
|
|
81
|
+
details: value.details,
|
|
82
|
+
action_type: value.action_type,
|
|
83
|
+
description: value.description,
|
|
84
|
+
execute_at: timestamp_to_date(value.execute_at, "execute_at"),
|
|
85
|
+
status: value.status,
|
|
86
|
+
attempt_count: typeof value.attempt_count === "number" ? value.attempt_count : 0,
|
|
87
|
+
created_at: timestamp_to_date(value.created_at, "created_at"),
|
|
88
|
+
updated_at: timestamp_to_date(value.updated_at, "updated_at"),
|
|
89
|
+
started_at: optional_timestamp_to_date(value.started_at, "started_at"),
|
|
90
|
+
completed_at: optional_timestamp_to_date(value.completed_at, "completed_at"),
|
|
91
|
+
cancelled_at: optional_timestamp_to_date(value.cancelled_at, "cancelled_at"),
|
|
92
|
+
failed_at: optional_timestamp_to_date(value.failed_at, "failed_at"),
|
|
93
|
+
error: typeof value.error === "string" ? value.error : undefined,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const assert_status = (key, actual, allowed) => {
|
|
97
|
+
if (!allowed.includes(actual)) {
|
|
98
|
+
throw new Error(`postponed action '${key}' has status '${String(actual)}'; expected ${allowed.join(" or ")}`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const get_postponed_action_core = async (key) => {
|
|
102
|
+
const snapshot = await get_ref(key).get();
|
|
103
|
+
return snapshot.exists ? to_postponed_action(snapshot) : null;
|
|
104
|
+
};
|
|
105
|
+
const add_postponed_action_core = async (input) => {
|
|
106
|
+
validate_details(input.details);
|
|
107
|
+
validate_text(input.action_type, "action_type");
|
|
108
|
+
validate_text(input.description, "description");
|
|
109
|
+
const ref = get_ref(input.key);
|
|
110
|
+
const execute_at = (0, exports.resolve_postponed_action_time)(input.execute_at);
|
|
111
|
+
const now = new Date();
|
|
112
|
+
return firebase_helpers_1.db.runTransaction(async (transaction) => {
|
|
113
|
+
const snapshot = await transaction.get(ref);
|
|
114
|
+
if (snapshot.exists) {
|
|
115
|
+
assert_status(input.key, snapshot.get("status"), [PostponedActionStatus.pending]);
|
|
116
|
+
transaction.update(ref, {
|
|
117
|
+
details: input.details,
|
|
118
|
+
action_type: input.action_type,
|
|
119
|
+
description: input.description,
|
|
120
|
+
execute_at,
|
|
121
|
+
updated_at: now,
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
...to_postponed_action(snapshot),
|
|
125
|
+
details: input.details,
|
|
126
|
+
action_type: input.action_type,
|
|
127
|
+
description: input.description,
|
|
128
|
+
execute_at,
|
|
129
|
+
updated_at: now,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const action = {
|
|
133
|
+
key: input.key,
|
|
134
|
+
details: input.details,
|
|
135
|
+
action_type: input.action_type,
|
|
136
|
+
description: input.description,
|
|
137
|
+
execute_at,
|
|
138
|
+
status: PostponedActionStatus.pending,
|
|
139
|
+
attempt_count: 0,
|
|
140
|
+
created_at: now,
|
|
141
|
+
updated_at: now,
|
|
142
|
+
};
|
|
143
|
+
transaction.create(ref, action);
|
|
144
|
+
return action;
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
const update_postponed_action_core = async (key, input) => {
|
|
148
|
+
if (input.details === undefined && input.action_type === undefined && input.description === undefined && input.execute_at === undefined) {
|
|
149
|
+
throw new Error("postponed action update must contain details, action_type, description or execute_at");
|
|
150
|
+
}
|
|
151
|
+
if (input.details !== undefined)
|
|
152
|
+
validate_details(input.details);
|
|
153
|
+
if (input.action_type !== undefined)
|
|
154
|
+
validate_text(input.action_type, "action_type");
|
|
155
|
+
if (input.description !== undefined)
|
|
156
|
+
validate_text(input.description, "description");
|
|
157
|
+
const ref = get_ref(key);
|
|
158
|
+
await firebase_helpers_1.db.runTransaction(async (transaction) => {
|
|
159
|
+
const snapshot = await transaction.get(ref);
|
|
160
|
+
if (!snapshot.exists)
|
|
161
|
+
throw new Error(`postponed action '${key}' does not exist`);
|
|
162
|
+
assert_status(key, snapshot.get("status"), [PostponedActionStatus.pending]);
|
|
163
|
+
transaction.update(ref, {
|
|
164
|
+
...(input.details === undefined ? {} : { details: input.details }),
|
|
165
|
+
...(input.action_type === undefined ? {} : { action_type: input.action_type }),
|
|
166
|
+
...(input.description === undefined ? {} : { description: input.description }),
|
|
167
|
+
...(input.execute_at === undefined ? {} : { execute_at: (0, exports.resolve_postponed_action_time)(input.execute_at) }),
|
|
168
|
+
updated_at: new Date(),
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
const repostpone_postponed_action_core = async (key, execute_at) => {
|
|
173
|
+
const ref = get_ref(key);
|
|
174
|
+
await firebase_helpers_1.db.runTransaction(async (transaction) => {
|
|
175
|
+
const snapshot = await transaction.get(ref);
|
|
176
|
+
if (!snapshot.exists)
|
|
177
|
+
throw new Error(`postponed action '${key}' does not exist`);
|
|
178
|
+
assert_status(key, snapshot.get("status"), [
|
|
179
|
+
PostponedActionStatus.pending,
|
|
180
|
+
PostponedActionStatus.completed,
|
|
181
|
+
PostponedActionStatus.cancelled,
|
|
182
|
+
PostponedActionStatus.failed,
|
|
183
|
+
]);
|
|
184
|
+
transaction.update(ref, {
|
|
185
|
+
execute_at: (0, exports.resolve_postponed_action_time)(execute_at),
|
|
186
|
+
status: PostponedActionStatus.pending,
|
|
187
|
+
updated_at: new Date(),
|
|
188
|
+
started_at: firestore_1.FieldValue.delete(),
|
|
189
|
+
completed_at: firestore_1.FieldValue.delete(),
|
|
190
|
+
cancelled_at: firestore_1.FieldValue.delete(),
|
|
191
|
+
failed_at: firestore_1.FieldValue.delete(),
|
|
192
|
+
error: firestore_1.FieldValue.delete(),
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
const cancel_postponed_action_core = async (key) => {
|
|
197
|
+
const ref = get_ref(key);
|
|
198
|
+
await firebase_helpers_1.db.runTransaction(async (transaction) => {
|
|
199
|
+
const snapshot = await transaction.get(ref);
|
|
200
|
+
if (!snapshot.exists)
|
|
201
|
+
throw new Error(`postponed action '${key}' does not exist`);
|
|
202
|
+
assert_status(key, snapshot.get("status"), [PostponedActionStatus.pending]);
|
|
203
|
+
const now = new Date();
|
|
204
|
+
transaction.update(ref, { status: PostponedActionStatus.cancelled, cancelled_at: now, updated_at: now });
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
const complete_postponed_action_core = async (key) => {
|
|
208
|
+
const ref = get_ref(key);
|
|
209
|
+
await firebase_helpers_1.db.runTransaction(async (transaction) => {
|
|
210
|
+
const snapshot = await transaction.get(ref);
|
|
211
|
+
if (!snapshot.exists)
|
|
212
|
+
throw new Error(`postponed action '${key}' does not exist`);
|
|
213
|
+
assert_status(key, snapshot.get("status"), [PostponedActionStatus.processing]);
|
|
214
|
+
const now = new Date();
|
|
215
|
+
transaction.update(ref, { status: PostponedActionStatus.completed, completed_at: now, updated_at: now });
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
const fail_postponed_action_core = async (key, error) => {
|
|
219
|
+
const ref = get_ref(key);
|
|
220
|
+
await firebase_helpers_1.db.runTransaction(async (transaction) => {
|
|
221
|
+
const snapshot = await transaction.get(ref);
|
|
222
|
+
if (!snapshot.exists)
|
|
223
|
+
throw new Error(`postponed action '${key}' does not exist`);
|
|
224
|
+
assert_status(key, snapshot.get("status"), [PostponedActionStatus.processing]);
|
|
225
|
+
const now = new Date();
|
|
226
|
+
transaction.update(ref, {
|
|
227
|
+
status: PostponedActionStatus.failed,
|
|
228
|
+
failed_at: now,
|
|
229
|
+
updated_at: now,
|
|
230
|
+
error: error instanceof Error ? error.message : String(error),
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
managers_1.logger.error(`[PostponedActions] action '${key}' failed`, error);
|
|
234
|
+
};
|
|
235
|
+
const delete_postponed_action_core = async (key) => {
|
|
236
|
+
await get_ref(key).delete();
|
|
237
|
+
};
|
|
238
|
+
const claim_postponed_action_core = async (key, action_type, now = new Date()) => {
|
|
239
|
+
validate_text(action_type, "action_type");
|
|
240
|
+
const ref = get_ref(key);
|
|
241
|
+
return firebase_helpers_1.db.runTransaction(async (transaction) => {
|
|
242
|
+
const snapshot = await transaction.get(ref);
|
|
243
|
+
if (!snapshot.exists || snapshot.get("status") !== PostponedActionStatus.pending || snapshot.get("action_type") !== action_type) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
const action = to_postponed_action(snapshot);
|
|
247
|
+
if (action.execute_at.getTime() > now.getTime())
|
|
248
|
+
return null;
|
|
249
|
+
const claimed = {
|
|
250
|
+
...action,
|
|
251
|
+
status: PostponedActionStatus.processing,
|
|
252
|
+
attempt_count: action.attempt_count + 1,
|
|
253
|
+
started_at: now,
|
|
254
|
+
updated_at: now,
|
|
255
|
+
};
|
|
256
|
+
transaction.update(ref, {
|
|
257
|
+
status: claimed.status,
|
|
258
|
+
attempt_count: claimed.attempt_count,
|
|
259
|
+
started_at: now,
|
|
260
|
+
updated_at: now,
|
|
261
|
+
});
|
|
262
|
+
return claimed;
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
const claim_due_postponed_actions_core = async (action_type, limit = 100, now = new Date()) => {
|
|
266
|
+
validate_text(action_type, "action_type");
|
|
267
|
+
if (!Number.isInteger(limit) || limit <= 0) {
|
|
268
|
+
throw new Error("limit must be a positive integer");
|
|
269
|
+
}
|
|
270
|
+
const snapshot = await firebase_helpers_1.db
|
|
271
|
+
.collection(POSTPONED_ACTIONS_COLLECTION)
|
|
272
|
+
.where("action_type", "==", action_type)
|
|
273
|
+
.where("status", "==", PostponedActionStatus.pending)
|
|
274
|
+
.where("execute_at", "<=", now)
|
|
275
|
+
.orderBy("execute_at")
|
|
276
|
+
.limit(limit)
|
|
277
|
+
.get();
|
|
278
|
+
const claimed = await Promise.all(snapshot.docs.map((document) => claim_postponed_action_core(document.id, action_type, now)));
|
|
279
|
+
return claimed.filter((action) => action !== null);
|
|
280
|
+
};
|
|
281
|
+
const with_error_logging = (operation, action, get_key) => {
|
|
282
|
+
return async (...args) => {
|
|
283
|
+
try {
|
|
284
|
+
return await action(...args);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
const key = get_key?.(...args);
|
|
288
|
+
managers_1.logger.error(`[PostponedActions] ${operation} failed${key ? ` for '${key}'` : ""}`, error);
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
exports.get_postponed_action = with_error_logging("get", get_postponed_action_core, (key) => key);
|
|
294
|
+
exports.add_postponed_action = with_error_logging("add", add_postponed_action_core, (input) => input.key);
|
|
295
|
+
exports.update_postponed_action = with_error_logging("update", update_postponed_action_core, (key) => key);
|
|
296
|
+
exports.repostpone_postponed_action = with_error_logging("repostpone", repostpone_postponed_action_core, (key) => key);
|
|
297
|
+
exports.cancel_postponed_action = with_error_logging("cancel", cancel_postponed_action_core, (key) => key);
|
|
298
|
+
exports.complete_postponed_action = with_error_logging("complete", complete_postponed_action_core, (key) => key);
|
|
299
|
+
exports.fail_postponed_action = with_error_logging("mark as failed", fail_postponed_action_core, (key) => key);
|
|
300
|
+
exports.delete_postponed_action = with_error_logging("delete", delete_postponed_action_core, (key) => key);
|
|
301
|
+
exports.claim_postponed_action = with_error_logging("claim", claim_postponed_action_core, (key) => key);
|
|
302
|
+
exports.claim_due_postponed_actions = with_error_logging("claim due", claim_due_postponed_actions_core);
|
|
303
|
+
/**
|
|
304
|
+
* @example Add an action for a specific date and time.
|
|
305
|
+
* ```ts
|
|
306
|
+
* await postponed_actions.add({
|
|
307
|
+
* key: "subscription:123:expire",
|
|
308
|
+
* action_type: "subscription_expiration",
|
|
309
|
+
* description: "Expire subscription 123",
|
|
310
|
+
* details: { subscription_id: "123", notify_customer: true },
|
|
311
|
+
* execute_at: new Date("2026-08-01T12:00:00Z"),
|
|
312
|
+
* });
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @example Add an action relative to the current time. Adding the same key
|
|
316
|
+
* updates the pending action.
|
|
317
|
+
* ```ts
|
|
318
|
+
* await postponed_actions.add({
|
|
319
|
+
* key: "invoice:456:reminder",
|
|
320
|
+
* action_type: "invoice_reminder",
|
|
321
|
+
* description: "Send invoice 456 reminder",
|
|
322
|
+
* details: { invoice_id: "456" },
|
|
323
|
+
* execute_at: { hours: 2, minutes: 30 },
|
|
324
|
+
* });
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
327
|
+
* @example Update, repostpone, or cancel a pending action.
|
|
328
|
+
* ```ts
|
|
329
|
+
* await postponed_actions.update("invoice:456:reminder", {
|
|
330
|
+
* description: "Send the final invoice reminder",
|
|
331
|
+
* execute_at: { minutes: 15 },
|
|
332
|
+
* });
|
|
333
|
+
* await postponed_actions.repostpone("invoice:456:reminder", { hours: 1 });
|
|
334
|
+
* await postponed_actions.cancel("invoice:456:reminder");
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @example Claim and execute due actions. Claiming is atomic, so concurrent
|
|
338
|
+
* workers cannot claim the same action.
|
|
339
|
+
* ```ts
|
|
340
|
+
* const actions = await postponed_actions.claim_due("invoice_reminder", 25);
|
|
341
|
+
* for (const action of actions) {
|
|
342
|
+
* try {
|
|
343
|
+
* await execute_action(action.details);
|
|
344
|
+
* await postponed_actions.complete(action.key);
|
|
345
|
+
* } catch (error) {
|
|
346
|
+
* await postponed_actions.fail(action.key, error);
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
exports.postponed_actions = {
|
|
352
|
+
get: exports.get_postponed_action,
|
|
353
|
+
add: exports.add_postponed_action,
|
|
354
|
+
update: exports.update_postponed_action,
|
|
355
|
+
repostpone: exports.repostpone_postponed_action,
|
|
356
|
+
cancel: exports.cancel_postponed_action,
|
|
357
|
+
complete: exports.complete_postponed_action,
|
|
358
|
+
fail: exports.fail_postponed_action,
|
|
359
|
+
delete: exports.delete_postponed_action,
|
|
360
|
+
claim: exports.claim_postponed_action,
|
|
361
|
+
claim_due: exports.claim_due_postponed_actions,
|
|
362
|
+
};
|
|
363
|
+
//# sourceMappingURL=postponed_actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postponed_actions.js","sourceRoot":"","sources":["../../../src/helpers/postponed_actions.ts"],"names":[],"mappings":";;;AAAA,wDAAiE;AACjE,yDAAwC;AAExC,0CAAqC;AAErC,MAAM,4BAA4B,GAAG,sBAAsB,CAAC;AAE5D,IAAY,qBAMX;AAND,WAAY,qBAAqB;IAC7B,4CAAmB,CAAA;IACnB,kDAAyB,CAAA;IACzB,gDAAuB,CAAA;IACvB,gDAAuB,CAAA;IACvB,0CAAiB,CAAA;AACrB,CAAC,EANW,qBAAqB,qCAArB,qBAAqB,QAMhC;AAsCD,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,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AAE,0BAA0B,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AACvG,QAAA,uBAAuB,GAAG,kBAAkB,CAAC,QAAQ,EAAE,4BAA4B,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AACnG,QAAA,sBAAsB,GAAG,kBAAkB,CAAC,OAAO,EAAE,2BAA2B,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AAChG,QAAA,2BAA2B,GAAG,kBAAkB,CAAC,WAAW,EAAE,gCAAgC,CAAC,CAAC;AAE7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACU,QAAA,iBAAiB,GAAG;IAC7B,GAAG,EAAE,4BAAoB;IACzB,GAAG,EAAE,4BAAoB;IACzB,MAAM,EAAE,+BAAuB;IAC/B,UAAU,EAAE,mCAA2B;IACvC,MAAM,EAAE,+BAAuB;IAC/B,QAAQ,EAAE,iCAAyB;IACnC,IAAI,EAAE,6BAAqB;IAC3B,MAAM,EAAE,+BAAuB;IAC/B,KAAK,EAAE,8BAAsB;IAC7B,SAAS,EAAE,mCAA2B;CACzC,CAAC"}
|
|
@@ -6,7 +6,8 @@ export declare enum TaskName {
|
|
|
6
6
|
collect_charge_cdrs = "collect_charge_cdrs",
|
|
7
7
|
auto_connect_to_call_center = "auto_connect_to_call_center",
|
|
8
8
|
make_erm_ev_events = "make_erm_ev_events",
|
|
9
|
-
collect_jimi_cars_odometer = "collect_jimi_cars_odometer"
|
|
9
|
+
collect_jimi_cars_odometer = "collect_jimi_cars_odometer",
|
|
10
|
+
send_email_polygon_left = "send_email_polygon_left"
|
|
10
11
|
}
|
|
11
12
|
export declare enum TaskStatus {
|
|
12
13
|
running = "running",
|
|
@@ -16,6 +16,7 @@ var TaskName;
|
|
|
16
16
|
TaskName["auto_connect_to_call_center"] = "auto_connect_to_call_center";
|
|
17
17
|
TaskName["make_erm_ev_events"] = "make_erm_ev_events";
|
|
18
18
|
TaskName["collect_jimi_cars_odometer"] = "collect_jimi_cars_odometer";
|
|
19
|
+
TaskName["send_email_polygon_left"] = "send_email_polygon_left";
|
|
19
20
|
})(TaskName || (exports.TaskName = TaskName = {}));
|
|
20
21
|
var TaskStatus;
|
|
21
22
|
(function (TaskStatus) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks_helpers.js","sourceRoot":"","sources":["../../../src/helpers/tasks_helpers.ts"],"names":[],"mappings":";;;;;;AACA,0CAAoD;AACpD,yDAA+E;AAC/E,oEAAmC;AAEnC,IAAY,
|
|
1
|
+
{"version":3,"file":"tasks_helpers.js","sourceRoot":"","sources":["../../../src/helpers/tasks_helpers.ts"],"names":[],"mappings":";;;;;;AACA,0CAAoD;AACpD,yDAA+E;AAC/E,oEAAmC;AAEnC,IAAY,QASX;AATD,WAAY,QAAQ;IAChB,6CAAiC,CAAA;IACjC,6DAAiD,CAAA;IACjD,iEAAqD,CAAA;IACrD,uDAA2C,CAAA;IAC3C,uEAA2D,CAAA;IAC3D,qDAAyC,CAAA;IACzC,qEAAyD,CAAA;IACzD,+DAAmD,CAAA;AACvD,CAAC,EATW,QAAQ,wBAAR,QAAQ,QASnB;AAED,IAAY,UAKX;AALD,WAAY,UAAU;IAClB,iCAAmB,CAAA;IACnB,qCAAuB,CAAA;IACvB,+BAAiB,CAAA;IACjB,uCAAyB,CAAA;AAC7B,CAAC,EALW,UAAU,0BAAV,UAAU,QAKrB;AAID,MAAM,uBAAuB,GAAG,CAAC,SAAmB,EAAE,IAA0B,EAAE,EAAE;IAChF,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,wBAAa,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;SAAM,CAAC;QACJ,wBAAa,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;AACL,CAAC,CAAC;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QACtE,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC,CAAC;AAVW,QAAA,0BAA0B,8BAUrC;AAEK,MAAM,yBAAyB,GAAG,KAAK,EAAE,SAAmB,EAAE,IAA0B,EAAmB,EAAE;IAChH,MAAM,MAAM,GAAG,wBAAK,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,SAAS,OAAO,CAAC,CAAC;IAEzD,IAAI,CAAC;QACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC7D,CAAC;QACD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/C,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACzB,WAAW,EAAE,kBAAkB;SAClC,CAAC,CAAC;QACH,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC;YACzC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;SAChD,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,iBAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;QAC/D,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC,CAAC;AAtBW,QAAA,yBAAyB,6BAsBpC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { TObject } from "akeyless-types-commons";
|
|
2
|
+
export declare enum PostponedActionStatus {
|
|
3
|
+
pending = "pending",
|
|
4
|
+
processing = "processing",
|
|
5
|
+
completed = "completed",
|
|
6
|
+
cancelled = "cancelled",
|
|
7
|
+
failed = "failed"
|
|
8
|
+
}
|
|
9
|
+
export type PostponedActionTime = Date | string | {
|
|
10
|
+
minutes?: number;
|
|
11
|
+
hours?: number;
|
|
12
|
+
};
|
|
13
|
+
export type JsonPayload = TObject<any>;
|
|
14
|
+
export interface PostponedAction {
|
|
15
|
+
key: string;
|
|
16
|
+
details: JsonPayload;
|
|
17
|
+
action_type: string;
|
|
18
|
+
description: string;
|
|
19
|
+
execute_at: Date;
|
|
20
|
+
status: PostponedActionStatus;
|
|
21
|
+
attempt_count: number;
|
|
22
|
+
created_at: Date;
|
|
23
|
+
updated_at: Date;
|
|
24
|
+
started_at?: Date;
|
|
25
|
+
completed_at?: Date;
|
|
26
|
+
cancelled_at?: Date;
|
|
27
|
+
failed_at?: Date;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AddPostponedAction {
|
|
31
|
+
key: string;
|
|
32
|
+
details: JsonPayload;
|
|
33
|
+
action_type: string;
|
|
34
|
+
description: string;
|
|
35
|
+
execute_at: PostponedActionTime;
|
|
36
|
+
}
|
|
37
|
+
export interface UpdatePostponedAction {
|
|
38
|
+
details?: JsonPayload;
|
|
39
|
+
action_type?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
execute_at?: PostponedActionTime;
|
|
42
|
+
}
|
|
43
|
+
export declare const resolve_postponed_action_time: (value: PostponedActionTime, now?: Date) => Date;
|
|
44
|
+
export declare const get_postponed_action: (key: string) => Promise<PostponedAction | null>;
|
|
45
|
+
export declare const add_postponed_action: (input: AddPostponedAction) => Promise<PostponedAction>;
|
|
46
|
+
export declare const update_postponed_action: (key: string, input: UpdatePostponedAction) => Promise<void>;
|
|
47
|
+
export declare const repostpone_postponed_action: (key: string, execute_at: PostponedActionTime) => Promise<void>;
|
|
48
|
+
export declare const cancel_postponed_action: (key: string) => Promise<void>;
|
|
49
|
+
export declare const complete_postponed_action: (key: string) => Promise<void>;
|
|
50
|
+
export declare const fail_postponed_action: (key: string, error: unknown) => Promise<void>;
|
|
51
|
+
export declare const delete_postponed_action: (key: string) => Promise<void>;
|
|
52
|
+
export declare const claim_postponed_action: (key: string, action_type: string, now?: Date | undefined) => Promise<PostponedAction | null>;
|
|
53
|
+
export declare const claim_due_postponed_actions: (action_type: string, limit?: number | undefined, now?: Date | undefined) => Promise<PostponedAction[]>;
|
|
54
|
+
/**
|
|
55
|
+
* @example Add an action for a specific date and time.
|
|
56
|
+
* ```ts
|
|
57
|
+
* await postponed_actions.add({
|
|
58
|
+
* key: "subscription:123:expire",
|
|
59
|
+
* action_type: "subscription_expiration",
|
|
60
|
+
* description: "Expire subscription 123",
|
|
61
|
+
* details: { subscription_id: "123", notify_customer: true },
|
|
62
|
+
* execute_at: new Date("2026-08-01T12:00:00Z"),
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Add an action relative to the current time. Adding the same key
|
|
67
|
+
* updates the pending action.
|
|
68
|
+
* ```ts
|
|
69
|
+
* await postponed_actions.add({
|
|
70
|
+
* key: "invoice:456:reminder",
|
|
71
|
+
* action_type: "invoice_reminder",
|
|
72
|
+
* description: "Send invoice 456 reminder",
|
|
73
|
+
* details: { invoice_id: "456" },
|
|
74
|
+
* execute_at: { hours: 2, minutes: 30 },
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example Update, repostpone, or cancel a pending action.
|
|
79
|
+
* ```ts
|
|
80
|
+
* await postponed_actions.update("invoice:456:reminder", {
|
|
81
|
+
* description: "Send the final invoice reminder",
|
|
82
|
+
* execute_at: { minutes: 15 },
|
|
83
|
+
* });
|
|
84
|
+
* await postponed_actions.repostpone("invoice:456:reminder", { hours: 1 });
|
|
85
|
+
* await postponed_actions.cancel("invoice:456:reminder");
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Claim and execute due actions. Claiming is atomic, so concurrent
|
|
89
|
+
* workers cannot claim the same action.
|
|
90
|
+
* ```ts
|
|
91
|
+
* const actions = await postponed_actions.claim_due("invoice_reminder", 25);
|
|
92
|
+
* for (const action of actions) {
|
|
93
|
+
* try {
|
|
94
|
+
* await execute_action(action.details);
|
|
95
|
+
* await postponed_actions.complete(action.key);
|
|
96
|
+
* } catch (error) {
|
|
97
|
+
* await postponed_actions.fail(action.key, error);
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare const postponed_actions: {
|
|
103
|
+
get: (key: string) => Promise<PostponedAction | null>;
|
|
104
|
+
add: (input: AddPostponedAction) => Promise<PostponedAction>;
|
|
105
|
+
update: (key: string, input: UpdatePostponedAction) => Promise<void>;
|
|
106
|
+
repostpone: (key: string, execute_at: PostponedActionTime) => Promise<void>;
|
|
107
|
+
cancel: (key: string) => Promise<void>;
|
|
108
|
+
complete: (key: string) => Promise<void>;
|
|
109
|
+
fail: (key: string, error: unknown) => Promise<void>;
|
|
110
|
+
delete: (key: string) => Promise<void>;
|
|
111
|
+
claim: (key: string, action_type: string, now?: Date | undefined) => Promise<PostponedAction | null>;
|
|
112
|
+
claim_due: (action_type: string, limit?: number | undefined, now?: Date | undefined) => Promise<PostponedAction[]>;
|
|
113
|
+
};
|