Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

beat.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -*- coding: utf-8 -*-
  2. """
  3. The :program:`celery beat` command.
  4. .. program:: celery beat
  5. .. seealso::
  6. See :ref:`preload-options` and :ref:`daemon-options`.
  7. .. cmdoption:: --detach
  8. Detach and run in the background as a daemon.
  9. .. cmdoption:: -s, --schedule
  10. Path to the schedule database. Defaults to `celerybeat-schedule`.
  11. The extension '.db' may be appended to the filename.
  12. Default is {default}.
  13. .. cmdoption:: -S, --scheduler
  14. Scheduler class to use.
  15. Default is :class:`celery.beat.PersistentScheduler`.
  16. .. cmdoption:: --max-interval
  17. Max seconds to sleep between schedule iterations.
  18. .. cmdoption:: -f, --logfile
  19. Path to log file. If no logfile is specified, `stderr` is used.
  20. .. cmdoption:: -l, --loglevel
  21. Logging level, choose between `DEBUG`, `INFO`, `WARNING`,
  22. `ERROR`, `CRITICAL`, or `FATAL`.
  23. """
  24. from __future__ import absolute_import
  25. from functools import partial
  26. from celery.platforms import detached, maybe_drop_privileges
  27. from celery.bin.base import Command, Option, daemon_options
  28. __all__ = ['beat']
  29. class beat(Command):
  30. """Start the beat periodic task scheduler.
  31. Examples::
  32. celery beat -l info
  33. celery beat -s /var/run/celery/beat-schedule --detach
  34. celery beat -S djcelery.schedulers.DatabaseScheduler
  35. """
  36. doc = __doc__
  37. enable_config_from_cmdline = True
  38. supports_args = False
  39. def run(self, detach=False, logfile=None, pidfile=None, uid=None,
  40. gid=None, umask=None, working_directory=None, **kwargs):
  41. if not detach:
  42. maybe_drop_privileges(uid=uid, gid=gid)
  43. workdir = working_directory
  44. kwargs.pop('app', None)
  45. beat = partial(self.app.Beat,
  46. logfile=logfile, pidfile=pidfile, **kwargs)
  47. if detach:
  48. with detached(logfile, pidfile, uid, gid, umask, workdir):
  49. return beat().run()
  50. else:
  51. return beat().run()
  52. def get_options(self):
  53. c = self.app.conf
  54. return (
  55. (Option('--detach', action='store_true'),
  56. Option('-s', '--schedule',
  57. default=c.CELERYBEAT_SCHEDULE_FILENAME),
  58. Option('--max-interval', type='float'),
  59. Option('-S', '--scheduler', dest='scheduler_cls'),
  60. Option('-l', '--loglevel', default=c.CELERYBEAT_LOG_LEVEL)) +
  61. daemon_options(default_pidfile='celerybeat.pid') +
  62. tuple(self.app.user_options['beat'])
  63. )
  64. def main(app=None):
  65. beat(app=app).execute_from_commandline()
  66. if __name__ == '__main__': # pragma: no cover
  67. main()