<commit_before># -*- encoding: utf-8 -*-
#
# Here is implemented the preApplication and postApplication method
# along the Asynchronous event schedule

from twisted.application import app
from twisted.internet.error import CannotListenError
from twisted.internet.defer import inlineCallbacks
from apscheduler.scheduler import Scheduler

from globaleaks.utils import log, utc_future_date
from globaleaks.db import create_tables, check_schema_version, import_memory_variables
from globaleaks.settings import GLSetting

# The scheduler is a global variable, because can be used to force execution
__all__ = ['GLAsynchronous']

GLAsynchronous = Scheduler()

class GLBaseRunner(app.ApplicationRunner):
    """
    This is a specialized runner that is responsible for starting the specified
    service.
    The purpose of it is to do the equivalent of what would be done with
    launching twistd from command line (daemonizing the process, creating the
    PID file, etc).
    """
    def preApplication(self):
        """
        We don't actually want to override this method since there is nothing
        interesting to do in here.
        """
        log.debug("%s %s " % (__file__, __name__),
                  "Class GLBaseRunner", "preApplication")

    def postApplication(self):
        """
        We must place all the operations to be done before the starting of the
        application.
        Here we will take care of the launching of the reactor and the
        operations to be done after it's shutdown.
        """
        log.debug("%s %s " % (__file__, __name__),
                  "Class GLBaseRunner", "postApplication")


def start_asynchronous():
    """
    Initialize the asynchronous operation, scheduled in the system
    https://github.com/globaleaks/GLBackend/wiki/Asynchronous-and-synchronous-operation

    This method would be likely put in GLBaseRunner.postApplication, but is
    not executed by globaleaks.run_app, then is called by the
    OS-depenedent runner below
    """
    from globaleaks.jobs import session_management_sched, \
                                notification_sched, gpgexpire_sched, \
                                delivery_sched, cleaning_sched

    # When the application boot, maybe because has been after a restart, then
    # with the method *.force_execution, we reschedule the execution of all the
    # operations

    # start the scheduler, before add the Schedule job
    GLAsynchronous.start()

    # This maybe expanded for debug:
    # def event_debug_listener(event):
    #     if event.exception:
    #         Job failed
    #     else:
    #         Job success
    #         GLAsynchronous.print_jobs()
    # GLAsynchronous.add_listener(event_debug_listener,
    #       EVENT_JOB_EXECUTED | EVENT_JOB_ERROR | EVENT_JOB_MISSED)

    session_manage_sched = session_management_sched.APSSessionManagement()
    GLAsynchronous.add_interval_job(session_manage_sched.operation,
                                    minutes=GLSetting.session_management_minutes_delta,
                                    start_date=utc_future_date(seconds=3))

    deliver_sched = delivery_sched.APSDelivery()
    GLAsynchronous.add_interval_job(deliver_sched.operation,
                                    seconds=GLSetting.delivery_seconds_delta,
                                    start_date=utc_future_date(seconds=5))

    notify_sched = notification_sched.APSNotification()
    GLAsynchronous.add_interval_job(notify_sched.operation,
                                    minutes=GLSetting.notification_minutes_delta,
                                    start_date=utc_future_date(seconds=7))

    clean_sched = cleaning_sched.APSCleaning()
    GLAsynchronous.add_interval_job(clean_sched.operation,
                                    hours=GLSetting.cleaning_hours_delta,
                                    start_date=utc_future_date(seconds=10))

    expiration_sched = gpgexpire_sched.GPGExpireCheck()
    GLAsynchronous.add_interval_job(expiration_sched.operation,
                                    hours=23,
                                    start_date=utc_future_date(seconds=50))

    #stats_sched = statistics_sched.APSStatistics()
    #stats_sched.force_execution(GLAsynchronous, seconds=9)
    #GLAsynchronous.add_interval_job(stats_sched.operation, seconds=GLSetting.statistics_interval)

from twisted.scripts._twistd_unix import ServerOptions, UnixApplicationRunner
ServerOptions = ServerOptions
<commit_msg>disabled GPG expiration check after reporting of: https://github.com/globaleaks/GlobaLeaks/issues/606<commit_after># -*- encoding: utf-8 -*-
#
# Here is implemented the preApplication and postApplication method
# along the Asynchronous event schedule

from twisted.application import app
from twisted.internet.error import CannotListenError
from twisted.internet.defer import inlineCallbacks
from apscheduler.scheduler import Scheduler

from globaleaks.utils import log, utc_future_date
from globaleaks.db import create_tables, check_schema_version, import_memory_variables
from globaleaks.settings import GLSetting

# The scheduler is a global variable, because can be used to force execution
__all__ = ['GLAsynchronous']

GLAsynchronous = Scheduler()

class GLBaseRunner(app.ApplicationRunner):
    """
    This is a specialized runner that is responsible for starting the specified
    service.
    The purpose of it is to do the equivalent of what would be done with
    launching twistd from command line (daemonizing the process, creating the
    PID file, etc).
    """
    def preApplication(self):
        """
        We don't actually want to override this method since there is nothing
        interesting to do in here.
        """
        log.debug("%s %s " % (__file__, __name__),
                  "Class GLBaseRunner", "preApplication")

    def postApplication(self):
        """
        We must place all the operations to be done before the starting of the
        application.
        Here we will take care of the launching of the reactor and the
        operations to be done after it's shutdown.
        """
        log.debug("%s %s " % (__file__, __name__),
                  "Class GLBaseRunner", "postApplication")


def start_asynchronous():
    """
    Initialize the asynchronous operation, scheduled in the system
    https://github.com/globaleaks/GLBackend/wiki/Asynchronous-and-synchronous-operation

    This method would be likely put in GLBaseRunner.postApplication, but is
    not executed by globaleaks.run_app, then is called by the
    OS-depenedent runner below
    """
    from globaleaks.jobs import session_management_sched, \
                                notification_sched, gpgexpire_sched, \
                                delivery_sched, cleaning_sched

    # When the application boot, maybe because has been after a restart, then
    # with the method *.force_execution, we reschedule the execution of all the
    # operations

    # start the scheduler, before add the Schedule job
    GLAsynchronous.start()

    # This maybe expanded for debug:
    # def event_debug_listener(event):
    #     if event.exception:
    #         Job failed
    #     else:
    #         Job success
    #         GLAsynchronous.print_jobs()
    # GLAsynchronous.add_listener(event_debug_listener,
    #       EVENT_JOB_EXECUTED | EVENT_JOB_ERROR | EVENT_JOB_MISSED)

    session_manage_sched = session_management_sched.APSSessionManagement()
    GLAsynchronous.add_interval_job(session_manage_sched.operation,
                                    minutes=GLSetting.session_management_minutes_delta,
                                    start_date=utc_future_date(seconds=3))

    deliver_sched = delivery_sched.APSDelivery()
    GLAsynchronous.add_interval_job(deliver_sched.operation,
                                    seconds=GLSetting.delivery_seconds_delta,
                                    start_date=utc_future_date(seconds=5))

    notify_sched = notification_sched.APSNotification()
    GLAsynchronous.add_interval_job(notify_sched.operation,
                                    minutes=GLSetting.notification_minutes_delta,
                                    start_date=utc_future_date(seconds=7))

    clean_sched = cleaning_sched.APSCleaning()
    GLAsynchronous.add_interval_job(clean_sched.operation,
                                    hours=GLSetting.cleaning_hours_delta,
                                    start_date=utc_future_date(seconds=10))

    # expiration_sched = gpgexpire_sched.GPGExpireCheck()
    # GLAsynchronous.add_interval_job(expiration_sched.operation,
    #                                 hours=23,
    #                                 start_date=utc_future_date(seconds=50))

    #stats_sched = statistics_sched.APSStatistics()
    #stats_sched.force_execution(GLAsynchronous, seconds=9)
    #GLAsynchronous.add_interval_job(stats_sched.operation, seconds=GLSetting.statistics_interval)

from twisted.scripts._twistd_unix import ServerOptions, UnixApplicationRunner
ServerOptions = ServerOptions

{'fraction_non_alphanumeric': 0.06390728476821192, 'fraction_numerical': 0.0027593818984547464, 'mean_word_length': 2.715047150471505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '768513', 'n_tokens_mistral': 2432, 'n_tokens_neox': 2327, 'n_words': 623}