psgeorge
psgeorge
Explore posts from servers
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
Thanks @Melissa
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
Thanks Brody
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
No description
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
But when I set this up it was the recommended way of doing things
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
kind of irrelevent, I had to disable my daily notifications cronjob because overdoing backups is fine, overdoing sending users 100 notifications a day is not fine
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
No description
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
Wasn't sure even railway would tbh
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
No description
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
Invited, link to the folder that has the cronjobs in it
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
I can't tell you how much I would love to not have to move off railway, its such a great product aside this phantom behaviour!
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
import { backup } from "./backup";

const tryBackup = async () => {
try {
await backup();
} catch (error) {
console.error("Error while running backup: ", error)
}
}

console.log("Running backup cron ...")
tryBackup();
import { backup } from "./backup";

const tryBackup = async () => {
try {
await backup();
} catch (error) {
console.error("Error while running backup: ", error)
}
}

console.log("Running backup cron ...")
tryBackup();
🤔 I'm pretty sure its not an issue on my end, because this was literally working for months, before it started breaking (with me having made no changes).
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
cronSchedule="0 5 * * *"
startCommand = "node dist/index.js"
replicas = 1
cronSchedule="0 5 * * *"
startCommand = "node dist/index.js"
replicas = 1
import { PutObjectCommand, S3Client, S3ClientConfig } from "@aws-sdk/client-s3";
import { createReadStream, unlink } from "fs";

import { env } from "./env";

const uploadToS3 = async ({ name, path }: {name: string, path: string}) => {
console.log("Uploading backup to S3...");

const bucket = env.AWS_S3_BUCKET;

const clientOptions: S3ClientConfig = {
region: env.AWS_S3_REGION,
}

if (env.AWS_S3_ENDPOINT) {
console.log(`Using custom endpoint: ${env.AWS_S3_ENDPOINT}`)
clientOptions['endpoint'] = env.AWS_S3_ENDPOINT;
}

const client = new S3Client(clientOptions);

await client.send(
new PutObjectCommand({
Bucket: bucket,
Key: name,
Body: createReadStream(path),
})
)

console.log("Backup uploaded to S3...");
}

const dumpToFile = async (path: string) => {
console.log("Dumping DB to file...");

await new Promise((resolve, reject) => {
exec(
`pg_dump ${env.BACKUP_DATABASE_URL} -Fc > ${path}`,
(error, stdout, stderr) => {
if (error) {
reject({ error: JSON.stringify(error), stderr });
return;
}

resolve(undefined);
}
);
});

console.log("DB dumped to file...");
}

const deleteFile = async (path: string) => {
console.log("Deleting file...");
await new Promise((resolve, reject) => {
unlink(path, (err) => {
reject({ error: JSON.stringify(err) });
return;
});
resolve(undefined);
})
}

export const backup = async () => {
console.log("Initiating DB backup...")

const date = new Date().toISOString()
const timestamp = date.replace(/[:.]+/g, '-')
const filename = `backup-${timestamp}.dump`
const filepath = `/tmp/${filename}`

await dumpToFile(filepath)
await uploadToS3({name: filename, path: filepath})
await deleteFile(filepath)

console.log("DB backup complete...")
}
import { PutObjectCommand, S3Client, S3ClientConfig } from "@aws-sdk/client-s3";
import { createReadStream, unlink } from "fs";

import { env } from "./env";

const uploadToS3 = async ({ name, path }: {name: string, path: string}) => {
console.log("Uploading backup to S3...");

const bucket = env.AWS_S3_BUCKET;

const clientOptions: S3ClientConfig = {
region: env.AWS_S3_REGION,
}

if (env.AWS_S3_ENDPOINT) {
console.log(`Using custom endpoint: ${env.AWS_S3_ENDPOINT}`)
clientOptions['endpoint'] = env.AWS_S3_ENDPOINT;
}

const client = new S3Client(clientOptions);

await client.send(
new PutObjectCommand({
Bucket: bucket,
Key: name,
Body: createReadStream(path),
})
)

console.log("Backup uploaded to S3...");
}

const dumpToFile = async (path: string) => {
console.log("Dumping DB to file...");

await new Promise((resolve, reject) => {
exec(
`pg_dump ${env.BACKUP_DATABASE_URL} -Fc > ${path}`,
(error, stdout, stderr) => {
if (error) {
reject({ error: JSON.stringify(error), stderr });
return;
}

resolve(undefined);
}
);
});

console.log("DB dumped to file...");
}

const deleteFile = async (path: string) => {
console.log("Deleting file...");
await new Promise((resolve, reject) => {
unlink(path, (err) => {
reject({ error: JSON.stringify(err) });
return;
});
resolve(undefined);
})
}

export const backup = async () => {
console.log("Initiating DB backup...")

const date = new Date().toISOString()
const timestamp = date.replace(/[:.]+/g, '-')
const filename = `backup-${timestamp}.dump`
const filepath = `/tmp/${filename}`

await dumpToFile(filepath)
await uploadToS3({name: filename, path: filepath})
await deleteFile(filepath)

console.log("DB backup complete...")
}
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
It's all as basic as could be
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
Sure I can add you to the repo if you give me your GH name, and then link you to code I'm using
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
e.g. a 1GB backup that decides to run 10x a minute between 2am and 4am as above is not ok
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
@Brody ☝️ I had to disable my notifications cron completely until I move it to a separate provider. DB backups are less harmful but it could still DDOS my database / cost me a ton of money if I had more users / data
53 replies
RRailway
Created by psgeorge on 1/12/2024 in #✋|help
Cronjob code executing every 13 seconds instead of on the schedule 0 13 * * *
No description
53 replies