mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix postgres
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
import logger from '../Utils/Logger';
|
||||
import { dataSourceOptions, testDataSourceOptions } from './PostgresConfig';
|
||||
import Sleep from "Common/Types/Sleep"
|
||||
import Sleep from 'Common/Types/Sleep';
|
||||
|
||||
export default class Database {
|
||||
private dataSource!: DataSource | null;
|
||||
@@ -25,41 +25,38 @@ export default class Database {
|
||||
public async connect(
|
||||
dataSourceOptions: DataSourceOptions
|
||||
): Promise<DataSource> {
|
||||
|
||||
let retry = 0;
|
||||
let retry: number = 0;
|
||||
|
||||
try {
|
||||
const connectToDatabase: Function =
|
||||
async (): Promise<DataSource> => {
|
||||
try {
|
||||
const PostgresDataSource: DataSource = new DataSource(
|
||||
dataSourceOptions
|
||||
);
|
||||
const dataSource: DataSource =
|
||||
await PostgresDataSource.initialize();
|
||||
logger.info('Postgres Database Connected');
|
||||
this.dataSource = dataSource;
|
||||
return dataSource;
|
||||
} catch (err) {
|
||||
if (retry < 3) {
|
||||
logger.info(
|
||||
'Cannot connect to Postgres. Retrying again in 5 seconds'
|
||||
);
|
||||
// sleep for 5 seconds.
|
||||
|
||||
const connectToDatabase: Function = async (): Promise<DataSource> => {
|
||||
await Sleep.sleep(5000);
|
||||
|
||||
try {
|
||||
const PostgresDataSource: DataSource = new DataSource(
|
||||
dataSourceOptions
|
||||
);
|
||||
const dataSource: DataSource =
|
||||
await PostgresDataSource.initialize();
|
||||
logger.info('Postgres Database Connected');
|
||||
this.dataSource = dataSource;
|
||||
return dataSource;
|
||||
} catch (err) {
|
||||
if(retry<3){
|
||||
logger.info("Cannot connect to Postgres. Retrying again in 5 seconds");
|
||||
// sleep for 5 seconds.
|
||||
|
||||
await Sleep.sleep(5000);
|
||||
|
||||
retry++;
|
||||
return await connectToDatabase();
|
||||
}else{
|
||||
throw err;
|
||||
retry++;
|
||||
return await connectToDatabase();
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return await connectToDatabase();
|
||||
|
||||
} catch (err) {
|
||||
|
||||
logger.error('Postgres Database Connection Failed');
|
||||
logger.error(err);
|
||||
throw err;
|
||||
|
||||
@@ -21,11 +21,9 @@ export default abstract class Redis {
|
||||
}
|
||||
|
||||
public static async connect(): Promise<RedisClientType> {
|
||||
|
||||
let retry = 0;
|
||||
let retry: number = 0;
|
||||
|
||||
try {
|
||||
|
||||
this.client = createClient({
|
||||
password: RedisPassword,
|
||||
socket: {
|
||||
@@ -34,23 +32,26 @@ export default abstract class Redis {
|
||||
},
|
||||
});
|
||||
|
||||
const connectToDatabase: Function = async (client: RedisClientType): Promise<void> => {
|
||||
const connectToDatabase: Function = async (
|
||||
client: RedisClientType
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await client.connect();
|
||||
} catch (err) {
|
||||
if (retry < 3) {
|
||||
logger.info("Cannot connect to Redis. Retrying again in 5 seconds");
|
||||
// sleep for 5 seconds.
|
||||
logger.info(
|
||||
'Cannot connect to Redis. Retrying again in 5 seconds'
|
||||
);
|
||||
// sleep for 5 seconds.
|
||||
|
||||
await Sleep.sleep(5000);
|
||||
|
||||
retry++;
|
||||
return await connectToDatabase(client);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await connectToDatabase(this.client);
|
||||
|
||||
|
||||
@@ -96,8 +96,6 @@ export class BillingService {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
let trialDate: Date | null = null;
|
||||
|
||||
if (typeof trial === Typeof.Boolean) {
|
||||
@@ -110,7 +108,7 @@ export class BillingService {
|
||||
|
||||
const subscriptionParams: Stripe.SubscriptionCreateParams = {
|
||||
customer: customerId,
|
||||
|
||||
|
||||
items: [
|
||||
{
|
||||
price: isYearly
|
||||
@@ -125,11 +123,10 @@ export class BillingService {
|
||||
: 'now',
|
||||
};
|
||||
|
||||
if(defaultPaymentMethodId){
|
||||
if (defaultPaymentMethodId) {
|
||||
subscriptionParams.default_payment_method = defaultPaymentMethodId;
|
||||
}
|
||||
|
||||
|
||||
const subscription: Stripe.Response<Stripe.Subscription> =
|
||||
await this.stripe.subscriptions.create(subscriptionParams);
|
||||
|
||||
@@ -179,7 +176,6 @@ export class BillingService {
|
||||
id: string;
|
||||
trialEndsAt?: Date | undefined;
|
||||
}> {
|
||||
|
||||
if (!this.isBillingEnabled()) {
|
||||
throw new BadDataException(
|
||||
'Billing is not enabled for this server.'
|
||||
@@ -191,13 +187,12 @@ export class BillingService {
|
||||
|
||||
if (!subscription) {
|
||||
throw new BadDataException('Subscription not found');
|
||||
}
|
||||
}
|
||||
|
||||
const paymentMethods: Array<PaymentMethod> = await this.getPaymentMethods(subscription.customer.toString());
|
||||
const paymentMethods: Array<PaymentMethod> =
|
||||
await this.getPaymentMethods(subscription.customer.toString());
|
||||
|
||||
if (
|
||||
paymentMethods.length === 0
|
||||
) {
|
||||
if (paymentMethods.length === 0) {
|
||||
throw new BadDataException(
|
||||
'No payment methods added. Please add your card to this project to change your plan'
|
||||
);
|
||||
@@ -205,7 +200,7 @@ export class BillingService {
|
||||
|
||||
await this.cancelSubscription(subscriptionId);
|
||||
|
||||
if(endTrialAt && !OneUptimeDate.isInTheFuture(endTrialAt)){
|
||||
if (endTrialAt && !OneUptimeDate.isInTheFuture(endTrialAt)) {
|
||||
endTrialAt = undefined;
|
||||
}
|
||||
|
||||
@@ -319,10 +314,6 @@ export class BillingService {
|
||||
});
|
||||
});
|
||||
|
||||
console.log("Payment methofs");
|
||||
console.log(paymenMethods);
|
||||
console.log(customerId);
|
||||
|
||||
return paymenMethods;
|
||||
}
|
||||
|
||||
@@ -351,9 +342,9 @@ export class BillingService {
|
||||
'Billing is not enabled for this server.'
|
||||
);
|
||||
}
|
||||
try{
|
||||
try {
|
||||
await this.stripe.subscriptions.del(subscriptionId);
|
||||
}catch(err){
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,6 @@ export class Service extends DatabaseService<Model> {
|
||||
): Promise<OnUpdate<Model>> {
|
||||
if (IsBillingEnabled) {
|
||||
if (updateBy.data.paymentProviderPlanId) {
|
||||
|
||||
// payment provider id changed.
|
||||
const project: Model | null = await this.findOneById({
|
||||
id: new ObjectID(updateBy.query._id! as string),
|
||||
|
||||
@@ -174,9 +174,10 @@ const DashboardProjectPicker: FunctionComponent<ComponentProps> = (
|
||||
? 'Custom Price'
|
||||
: isSubsriptionPlanYearly
|
||||
? '$' +
|
||||
(
|
||||
plan.getYearlySubscriptionAmountInUSD()
|
||||
).toString() +"/mo billed yearly"
|
||||
plan
|
||||
.getYearlySubscriptionAmountInUSD()
|
||||
.toString() +
|
||||
'/mo billed yearly'
|
||||
: '$' +
|
||||
plan
|
||||
.getMonthlySubscriptionAmountInUSD()
|
||||
@@ -184,7 +185,10 @@ const DashboardProjectPicker: FunctionComponent<ComponentProps> = (
|
||||
sideDescription: plan.isCustomPricing()
|
||||
? ''
|
||||
: isSubsriptionPlanYearly
|
||||
? `~ $${plan.getYearlySubscriptionAmountInUSD() * 12} per user / year`
|
||||
? `~ $${
|
||||
plan.getYearlySubscriptionAmountInUSD() *
|
||||
12
|
||||
} per user / year`
|
||||
: `/month per user`,
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -122,18 +122,23 @@ const Upgrade: FunctionComponent = (): ReactElement => {
|
||||
? 'Custom Price'
|
||||
: isSubsriptionPlanYearly
|
||||
? '$' +
|
||||
(
|
||||
plan.getYearlySubscriptionAmountInUSD()
|
||||
).toString() +"/mo billed yearly"
|
||||
: '$' +
|
||||
plan
|
||||
.getMonthlySubscriptionAmountInUSD()
|
||||
.toString(),
|
||||
sideDescription: plan.isCustomPricing()
|
||||
? ''
|
||||
: isSubsriptionPlanYearly
|
||||
? `~ $${plan.getYearlySubscriptionAmountInUSD() * 12} per user / year`
|
||||
: `/month per user`,
|
||||
plan
|
||||
.getYearlySubscriptionAmountInUSD()
|
||||
.toString() +
|
||||
'/mo billed yearly'
|
||||
: '$' +
|
||||
plan
|
||||
.getMonthlySubscriptionAmountInUSD()
|
||||
.toString(),
|
||||
sideDescription:
|
||||
plan.isCustomPricing()
|
||||
? ''
|
||||
: isSubsriptionPlanYearly
|
||||
? `~ $${
|
||||
plan.getYearlySubscriptionAmountInUSD() *
|
||||
12
|
||||
} per user / year`
|
||||
: `/month per user`,
|
||||
};
|
||||
}
|
||||
),
|
||||
|
||||
@@ -251,7 +251,7 @@ const MonitorIncidents: FunctionComponent<PageComponentProps> = (
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return <></>;
|
||||
},
|
||||
},
|
||||
|
||||
@@ -200,18 +200,22 @@ const Settings: FunctionComponent<ComponentProps> = (
|
||||
? 'Custom Price'
|
||||
: isSubsriptionPlanYearly
|
||||
? '$' +
|
||||
(
|
||||
plan.getYearlySubscriptionAmountInUSD()
|
||||
).toString() +"/mo billed yearly"
|
||||
: '$' +
|
||||
plan
|
||||
.getMonthlySubscriptionAmountInUSD()
|
||||
.toString(),
|
||||
sideDescription: plan.isCustomPricing()
|
||||
? ''
|
||||
: isSubsriptionPlanYearly
|
||||
? `~ $${plan.getYearlySubscriptionAmountInUSD() * 12} per user / year`
|
||||
: `/month per user`,
|
||||
plan
|
||||
.getYearlySubscriptionAmountInUSD()
|
||||
.toString() +
|
||||
'/mo billed yearly'
|
||||
: '$' +
|
||||
plan
|
||||
.getMonthlySubscriptionAmountInUSD()
|
||||
.toString(),
|
||||
sideDescription: plan.isCustomPricing()
|
||||
? ''
|
||||
: isSubsriptionPlanYearly
|
||||
? `~ $${
|
||||
plan.getYearlySubscriptionAmountInUSD() *
|
||||
12
|
||||
} per user / year`
|
||||
: `/month per user`,
|
||||
};
|
||||
}),
|
||||
title: 'Please select a plan.',
|
||||
|
||||
@@ -137,10 +137,10 @@ export default class RunWorkflow {
|
||||
|
||||
const runStack: RunStack = await this.makeRunStack(workflow.graph);
|
||||
|
||||
const getVariableResult: { storageMap: StorageMap, variables: Array<WorkflowVariable> } = await this.getVariables(
|
||||
workflow.projectId!,
|
||||
workflow.id!
|
||||
);
|
||||
const getVariableResult: {
|
||||
storageMap: StorageMap;
|
||||
variables: Array<WorkflowVariable>;
|
||||
} = await this.getVariables(workflow.projectId!, workflow.id!);
|
||||
|
||||
// get storage map with variables.
|
||||
const storageMap: StorageMap = getVariableResult.storageMap;
|
||||
@@ -163,8 +163,8 @@ export default class RunWorkflow {
|
||||
if (didWorkflowTimeOut) {
|
||||
throw new TimeoutException(
|
||||
'Workflow execution time was more than ' +
|
||||
runProps.timeout +
|
||||
'ms and workflow timed-out.'
|
||||
runProps.timeout +
|
||||
'ms and workflow timed-out.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,8 +176,8 @@ export default class RunWorkflow {
|
||||
if (componentsExecuted.includes(executeComponentId)) {
|
||||
throw new BadDataException(
|
||||
'Cyclic Workflow Detected. Cannot execute ' +
|
||||
executeComponentId +
|
||||
' when it has already been executed.'
|
||||
executeComponentId +
|
||||
' when it has already been executed.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -191,8 +191,8 @@ export default class RunWorkflow {
|
||||
if (!stackItem) {
|
||||
throw new BadDataException(
|
||||
'Component with ID ' +
|
||||
executeComponentId +
|
||||
' not found.'
|
||||
executeComponentId +
|
||||
' not found.'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ export default class RunWorkflow {
|
||||
this.log(result.returnValues);
|
||||
this.log(
|
||||
'Executing Port: ' + result.executePort?.title ||
|
||||
'<None>'
|
||||
'<None>'
|
||||
);
|
||||
|
||||
storageMap.local.components[stackItem.node.id] = {
|
||||
@@ -348,10 +348,8 @@ export default class RunWorkflow {
|
||||
}
|
||||
}
|
||||
|
||||
public cleanLogs(variables: Array<WorkflowVariable>) {
|
||||
|
||||
for (let i = 0; i < this.logs.length; i++) {
|
||||
|
||||
public cleanLogs(variables: Array<WorkflowVariable>): void {
|
||||
for (let i: number = 0; i < this.logs.length; i++) {
|
||||
if (!this.logs[i]) {
|
||||
continue;
|
||||
}
|
||||
@@ -359,8 +357,10 @@ export default class RunWorkflow {
|
||||
for (const variable of variables) {
|
||||
if (variable.isSecret) {
|
||||
if (this.logs[i]!.includes(variable.content!)) {
|
||||
console.log(this.logs[i]!);
|
||||
this.logs[i] = this.logs[i]!.replace(variable.content!, "xxxxxxxxxxxxxxx")
|
||||
this.logs[i] = this.logs[i]!.replace(
|
||||
variable.content!,
|
||||
'xxxxxxxxxxxxxxx'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,7 +481,7 @@ export default class RunWorkflow {
|
||||
public async getVariables(
|
||||
projectId: ObjectID,
|
||||
workflowId: ObjectID
|
||||
): Promise<{ storageMap: StorageMap, variables: Array<WorkflowVariable> }> {
|
||||
): Promise<{ storageMap: StorageMap; variables: Array<WorkflowVariable> }> {
|
||||
/// get local and global variables.
|
||||
const localVariables: Array<WorkflowVariable> =
|
||||
await WorkflowVariableService.findBy({
|
||||
@@ -538,7 +538,10 @@ export default class RunWorkflow {
|
||||
variable.content as string;
|
||||
}
|
||||
|
||||
return { storageMap: newStorageMap, variables: [...localVariables, ...globalVariables] };
|
||||
return {
|
||||
storageMap: newStorageMap,
|
||||
variables: [...localVariables, ...globalVariables],
|
||||
};
|
||||
}
|
||||
|
||||
public log(data: string | JSONObject | JSONArray | Exception): void {
|
||||
@@ -557,8 +560,8 @@ export default class RunWorkflow {
|
||||
} else {
|
||||
this.logs.push(
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() +
|
||||
': ' +
|
||||
JSON.stringify(data)
|
||||
': ' +
|
||||
JSON.stringify(data)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -632,7 +635,7 @@ export default class RunWorkflow {
|
||||
const trigger: any | undefined = nodes.find((n: any) => {
|
||||
return (
|
||||
(n.data as NodeDataProp).componentType ===
|
||||
ComponentType.Trigger &&
|
||||
ComponentType.Trigger &&
|
||||
(n.data as NodeDataProp).nodeType === NodeType.Node
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user