-
-
Notifications
You must be signed in to change notification settings - Fork 166
/
cron.js
147 lines (139 loc) · 3.86 KB
/
cron.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const CronJob = require('cron').CronJob
const models = require('./models')
const moment = require('moment')
const i18n = require('i18n')
const DeadlineMail = require('./modules/mail/deadline')
const TaskMail = require('./modules/mail/task')
const OrderCron = require('./cron/orderCron')
const bountyClosedNotPaidComment = require('./modules/bot/bountyClosedNotPaidComment')
i18n.configure({
directory: process.env.NODE_ENV !== 'production' ? `${__dirname}/locales` : `${__dirname}/locales/result`,
locales: process.env.NODE_ENV !== 'production' ? ['en'] : ['en', 'br'],
defaultLocale: 'en',
updateFiles: false
})
i18n.init()
const TaskCron = {
weeklyBounties: async () => {
const tasks = await models.Task.findAll({ where: {
value: {
$gt: 0
},
assigned: {
$eq: null
},
status: {
$eq: 'open'
}
},
include: [ models.User ]
})
if (tasks[0]) {
TaskMail.weeklyBounties({ tasks })
}
return tasks
},
latestTasks: async () => {
const tasks = await models.Task.findAll({
where: {
assigned: {
$eq: null
},
status: {
$eq: 'open'
}
},
limit: 5,
order: [['id', 'DESC']],
include: [ models.User ]
})
if (tasks[0]) {
TaskMail.weeklyLatest({ tasks })
}
return tasks
},
rememberDeadline: async () => {
const tasks = await models.Task.findAll({ where: {
status: 'in_progress',
deadline: {
$lt: moment(new Date()).format(),
$gt: moment(new Date()).subtract(2, 'days').format()
}
},
include: [ models.User ]
})
if (tasks[0]) {
tasks.map(async t => {
if (t.assigned) {
if (t.dataValues && t.assigned) {
const userAssigned = await models.Assign.findAll({ where: { id: t.assigned }, include: [models.User] })
if (userAssigned[0].dataValues) {
DeadlineMail.deadlineEndOwner(t.User.dataValues, t.dataValues, t.User.name || t.User.username)
DeadlineMail.deadlineEndAssigned(userAssigned[0].dataValues.User, t.dataValues, userAssigned[0].dataValues.User.dataValues.name)
}
}
}
})
}
return tasks
},
weeklyBountiesClosedNotPaid: async () => {
const tasks = await models.Task.findAll({
where: {
value: {
$gt: 0
},
status: {
$eq: 'closed'
},
paid: {
$not: true
}
},
include: [models.User]
})
if (tasks[0]) {
tasks.map(async t => {
let userInformation = {}
if (t.assigned) {
if (t.dataValues && t.assigned) {
const userAssigned = await models.Assign.findAll({ where: { id: t.assigned }, include: [models.User] })
if (userAssigned[0].dataValues && userAssigned[0].dataValues.User.provider === 'github') {
userInformation = userAssigned[0].dataValues.User
}
}
}
bountyClosedNotPaidComment(t, userInformation)
})
}
return tasks
},
}
const dailyJob = new CronJob({
// Seconds: 0-59 Minutes: 0-59 Hours: 0-23 Day of Month: 1-31 Months: 0-11 (Jan-Dec) Day of Week: 0-6 (Sun-Sat)
cronTime: '0 0 0 * * *', // everyday at 12:00AM
onTick: () => {
//TaskCron.rememberDeadline()
//OrderCron.verify()
OrderCron.checkExpiredPaypalOrders()
}
})
const weeklyJob = new CronJob({
cronTime: '5 8 * * 0',
onTick: () => {
TaskCron.weeklyBounties()
}
})
const weeklyJobLatest = new CronJob({
cronTime: '5 8 * * 4',
onTick: () => {
TaskCron.latestTasks()
}
})
const weeklyJobBountiesClosedNotPaid = new CronJob({
cronTime: '5 8 * * 0',
onTick: () => {
TaskCron.weeklyBountiesClosedNotPaid()
}
})
module.exports = { dailyJob, weeklyJob, weeklyJobLatest, weeklyJobBountiesClosedNotPaid, TaskCron, OrderCron }