Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

from __future__ import absolute_import 

 

from celery import Celery 

from ConfigParser import ConfigParser 

from datetime import timedelta 

from os import environ 

from os import path 

 

 

def load_ini(): 

    selected_ini = environ.get('BOOKIE_INI', 'bookie.ini') 

    if selected_ini is None: 

        msg = "Please set the BOOKIE_INI env variable!" 

        raise Exception(msg) 

 

    cfg = ConfigParser() 

    ini_path = path.join( 

        path.dirname( 

            path.dirname( 

                path.dirname(__file__) 

            ) 

        ), 

        selected_ini 

    ) 

    cfg.readfp(open(ini_path)) 

 

    # Hold onto the ini config. 

    return dict(cfg.items('app:bookie', raw=True)) 

 

 

INI = load_ini() 

 

 

celery = Celery( 

    'bookie.bcelery', 

    broker=INI.get('celery_broker'), 

    include=['bookie.bcelery.tasks']) 

 

# Optional configuration, see the application user guide. 

celery.conf.update( 

    CELERY_TASK_RESULT_EXPIRES=3600, 

    CELERY_RESULT_BACKEND=INI.get('celery_broker'), 

    CELERYBEAT_SCHEDULE={ 

        'hourly_stats': { 

            'task': 'bookie.bcelery.tasks.hourly_stats', 

            'schedule': timedelta(seconds=60*60), 

        }, 

        'fetch_unfetched': { 

            'task': 'bookie.bcelery.tasks.fetch_unfetched_bmark_content', 

            'schedule': timedelta(seconds=60), 

        }, 

    } 

) 

 

if __name__ == '__main__': 

    celery.start()