mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 11:36:45 +00:00
Fix Group dailies reset not working. (#7)
Fix group dailies not reset #2 --------- Co-authored-by: Adrian Winterstein <adrian@winterstein.biz> Co-authored-by: Saik0Shinigami
This commit is contained in:
parent
0155698572
commit
d2f4ee6f4f
4 changed files with 79 additions and 4 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -72,8 +72,18 @@ COPY --from=build /usr/src/habitica/website/ /var/lib/habitica/website/
|
|||
COPY --from=build /usr/src/habitica/package.json /var/lib/habitica/package.json
|
||||
COPY --from=build /usr/src/habitica/config.json /var/lib/habitica/config.json
|
||||
|
||||
CMD ["node", "/var/lib/habitica/website/transpiled-babel/index.js"]
|
||||
|
||||
# Copy the scripts and cron job for resetting group dailies on a daily basis
|
||||
RUN mkdir -p /var/lib/habitica/scripts/
|
||||
COPY --from=build /usr/src/habitica/scripts/team-cron.js /var/lib/habitica/scripts/team-cron.js
|
||||
COPY --from=build /usr/src/habitica/scripts/team-cron/run-team-cron.js /var/lib/habitica/
|
||||
RUN apt-get update && apt-get -y install cron
|
||||
RUN mkdir -p /etc/cron.d
|
||||
COPY --from=build /usr/src/habitica/scripts/team-cron/habiticateamcron /etc/cron.d/habiticateamcron
|
||||
RUN chmod 0644 /etc/cron.d/habiticateamcron
|
||||
RUN crontab /etc/cron.d/habiticateamcron
|
||||
|
||||
CMD sh -c 'printenv | grep -v "no_proxy" >> /etc/environment && /etc/init.d/cron start && node /var/lib/habitica/website/transpiled-babel/index.js'
|
||||
|
||||
|
||||
# Container for providing the build web component of Habitica
|
||||
|
|
|
|||
|
|
@ -100,11 +100,11 @@ async function updateTeamTasks (team) {
|
|||
return Promise.all(toSave);
|
||||
}
|
||||
|
||||
export default async function processTeamsCron () {
|
||||
module.exports = async function processTeamsCron() {
|
||||
const activeTeams = await Group.find({
|
||||
'purchased.plan.customerId': { $exists: true },
|
||||
}, { cron: 1, leader: 1, purchased: 1 }).exec();
|
||||
|
||||
const cronPromises = activeTeams.map(updateTeamTasks);
|
||||
return Promise.all(cronPromises);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
1
scripts/team-cron/habiticateamcron
Normal file
1
scripts/team-cron/habiticateamcron
Normal file
|
|
@ -0,0 +1 @@
|
|||
2 * * * * . /etc/environment; cd /var/lib/habitica && /usr/local/bin/node ./run-team-cron.js >> /var/log/cron.log 2>&1
|
||||
64
scripts/team-cron/run-team-cron.js
Normal file
64
scripts/team-cron/run-team-cron.js
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
const mongoose = require("mongoose");
|
||||
const nconf = require("nconf");
|
||||
|
||||
// Initialize nconf with hierarchical configuration
|
||||
|
||||
nconf
|
||||
.argv() // Command-line arguments first
|
||||
.env() // Environment variables second
|
||||
.file({
|
||||
// Configuration file third
|
||||
file: "config.json",
|
||||
})
|
||||
.defaults({
|
||||
// Default values last
|
||||
SESSION_SECRET_KEY: null,
|
||||
SESSION_SECRET_IV: null,
|
||||
});
|
||||
|
||||
// Get database URI
|
||||
const dbUri = nconf.get("NODE_DB_URI");
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// Connect to MongoDB and wait for connection
|
||||
await mongoose.connect(dbUri, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
});
|
||||
|
||||
console.log("Connected to MongoDB");
|
||||
|
||||
// Register babel after MongoDB connection
|
||||
require("@babel/register")({
|
||||
extensions: [".js"],
|
||||
presets: ["@babel/preset-env"],
|
||||
cache: false,
|
||||
});
|
||||
|
||||
console.log("Babel registered");
|
||||
|
||||
const processTeamsCron = require("./scripts/team-cron.js");
|
||||
|
||||
if (typeof processTeamsCron !== "function") {
|
||||
throw new Error("processTeamsCron is not properly exported");
|
||||
}
|
||||
|
||||
// Run the cron job
|
||||
console.log("Starting team cron processing...");
|
||||
await processTeamsCron();
|
||||
console.log("Team cron processing completed");
|
||||
|
||||
// Close the DB connection
|
||||
await mongoose.connection.close();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
if (mongoose.connection) {
|
||||
await mongoose.connection.close();
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Loading…
Reference in a new issue