/
make-crons.py
executable file
·93 lines (69 loc) · 1.96 KB
/
make-crons.py
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
#!/usr/bin/env python
import os
from string import Template
CRONS = {}
COMMON = {
'MANAGE': '/usr/bin/python26 manage.py',
'CRON': '$DJANGO cron',
'DJANGO': 'cd $KITSUNE; $MANAGE',
}
CRONS['support'] = {
'KITSUNE': '/data/www/support.allizom.org/kitsune',
}
CRONS['support-release'] = {
'KITSUNE': '/data/www/support-release.allizom.org/kitsune',
}
CRONS['prod'] = {
'KITSUNE': '/data/www/support.mozilla.com/kitsune',
}
# Update each dict with the values from common.
for key, dict_ in CRONS.items():
dict_.update(COMMON)
# Do any interpolation inside the keys.
for dict_ in CRONS.values():
while 1:
changed = False
for key, val in dict_.items():
new = Template(val).substitute(dict_)
if new != val:
changed = True
dict_[key] = new
if not changed:
break
cron = """\
#
# !!AUTO-GENERATED!! Edit scripts/crontab/make-crons.py instead.
#
MAILTO=cron-sumo@mozilla.com
HOME = /tmp
# Every minute!
* * * * * $CRON collect_tweets
# Every hour.
42 * * * * $DJANGO cleanup
# Every 2 hours.
1 */2 * * * $CRON calculate_related_documents
# Every 6 hours.
0 */6 * * * $DJANGO update_product_details -q > /dev/null
10 */6 * * * $CRON rebuild_kb
30 */6 * * * $CRON get_customercare_stats
40 */6 * * * $CRON purge_tweets
50 */6 * * * $CRON cache_top_contributors
# Once per day.
0 16 * * * $CRON reload_wiki_traffic_stats
40 1 * * * $CRON update_weekly_votes
42 0 * * * $CRON update_top_contributors
0 21 * * * $CRON cache_most_unhelpful_kb_articles
47 2 * * * $CRON remove_expired_registration_profiles
0 9 * * * $CRON update_visitors_metric
# Twice per week.
#05 01 * * 1,4 $CRON update_weekly_votes
# Once per week.
21 03 * * 3 $DJANGO purge_hashes
MAILTO=root
"""
def main():
for key, vals in CRONS.items():
path = os.path.join(os.path.dirname(__file__), key)
open(path, 'w').write(Template(cron).substitute(vals))
if __name__ == '__main__':
main()