forked from hasgeek/hasjob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·48 lines (36 loc) · 1.27 KB
/
manage.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import timedelta
from hasjob import app
from hasjob.models import db
import hasjob
import hasjob.forms as forms
import hasjob.models as models
import hasjob.views as views
from coaster.manage import Manager, init_manager
from coaster.utils import utcnow
periodic = Manager(usage="Periodic tasks from cron (with recommended intervals)")
@periodic.command
def sessions():
"""Sweep user sessions to close all inactive sessions (10m)"""
es = models.EventSession
# Close all sessions that have been inactive for >= 30 minutes
es.query.filter(
es.ended_at.is_(None), es.active_at < (utcnow() - timedelta(minutes=30))
).update({es.ended_at: es.active_at})
db.session.commit()
@periodic.command
def impressions():
"""Recount impressions for jobposts in the dirty list (5m)"""
views.helper.update_dirty_impression_counts()
@periodic.command
def campaignviews():
"""Reset campaign views after more than 30 days since last view (1d)"""
views.helper.reset_campaign_views()
if __name__ == '__main__':
db.init_app(app)
manager = init_manager(
app, db, hasjob=hasjob, models=models, forms=forms, views=views
)
manager.add_command('periodic', periodic)
manager.run()