Exemplo n.º 1
0
def publish_3pty_sub24(dbo):
    try:
        publishers = configuration.publishers_enabled(dbo)
        freq = configuration.publisher_sub24_frequency(dbo)
        hournow = dbo.now().hour
        al.debug("chosen freq %s, current hour %s" % (freq, hournow),
                 "cron.publish_3pty_sub24", dbo)
        if freq == 0:
            return  # 24 hour mode is covered by regular publish_3pty with the batch
        elif freq == 2 and hournow not in [
                0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22
        ]:
            return
        elif freq == 4 and hournow not in [1, 5, 9, 13, 17, 21]:
            return
        elif freq == 6 and hournow not in [3, 9, 13, 19]:
            return
        elif freq == 8 and hournow not in [1, 9, 17]:
            return
        elif freq == 12 and hournow not in [0, 12]:
            return
        for p in publishers.split(" "):
            if p in publish.PUBLISHER_LIST and publish.PUBLISHER_LIST[p][
                    "sub24hour"]:
                publish.start_publisher(dbo, p, user="******", newthread=False)
    except:
        em = str(sys.exc_info()[0])
        al.error(
            "FAIL: uncaught error running sub24 third party publishers: %s" %
            em, "cron.publish_3pty_sub24", dbo, sys.exc_info())
Exemplo n.º 2
0
def ttask(fn, dbo):
    """ Runs a function and times how long it takes """
    x = time.time()
    fn(dbo)
    elapsed = time.time() - x
    if elapsed > 10:
        al.warn("complete in %0.2f sec" % elapsed, fn.__name__, dbo)
    else:
        al.debug("complete in %0.2f sec" % elapsed, fn.__name__, dbo)
Exemplo n.º 3
0
def run(dbo, mode):
    # If the task is maint_db_install, then there won't be a
    # locale or timezone to read
    x = time.time()
    al.info("start %s" % mode, "cron.run", dbo)
    if mode == "maint_db_install":
        dbo.locale = LOCALE
        dbo.timezone = TIMEZONE
    else:
        # Get the locale and timezone from the system
        dbo.locale = configuration.locale(dbo)
        dbo.timezone = configuration.timezone(dbo)
        dbo.timezone_dst = configuration.timezone_dst(dbo)
    dbo.installpath = os.getcwd() + os.sep
    al.debug(
        "set locale and timezone for database: %s, %d" %
        (dbo.locale, dbo.timezone), "cron", dbo)
    if mode == "all":
        daily(dbo)
        reports_email(dbo)
        publish_html(dbo)
        publish_3pty(dbo)
    elif mode == "daily":
        daily(dbo)
    elif mode == "reports_email":
        reports_email(dbo)
    elif mode == "publish_3pty":
        publish_3pty(dbo)
    elif mode == "publish_3pty_sub24":
        publish_3pty_sub24(dbo)
    elif mode == "publish_html":
        publish_html(dbo)
    elif mode == "maint_import_report":
        maint_import_report(dbo)
    elif mode == "maint_recode_all":
        maint_recode_all(dbo)
    elif mode == "maint_recode_shelter":
        maint_recode_shelter(dbo)
    elif mode == "maint_scale_animal_images":
        maint_scale_animal_images(dbo)
    elif mode == "maint_scale_odts":
        maint_scale_odts(dbo)
    elif mode == "maint_scale_pdfs":
        maint_scale_pdfs(dbo)
    elif mode == "maint_switch_dbfs_storage":
        maint_switch_dbfs_storage(dbo)
    elif mode == "maint_variable_data":
        maint_variable_data(dbo)
    elif mode == "maint_animal_figures":
        maint_animal_figures(dbo)
    elif mode == "maint_animal_figures_annual":
        maint_animal_figures_annual(dbo)
    elif mode == "maint_db_diagnostic":
        maint_db_diagnostic(dbo)
    elif mode == "maint_db_fix_preferred_photos":
        maint_db_fix_preferred_photos(dbo)
    elif mode == "maint_db_dump":
        maint_db_dump(dbo)
    elif mode == "maint_db_dump_dbfs_base64":
        maint_db_dump_dbfs_base64(dbo)
    elif mode == "maint_db_dump_dbfs_files":
        maint_db_dump_dbfs_files(dbo)
    elif mode == "maint_db_dump_lookups":
        maint_db_dump_lookups(dbo)
    elif mode == "maint_db_dump_merge":
        maint_db_dump_merge(dbo)
    elif mode == "maint_db_dump_smcom":
        maint_db_dump_smcom(dbo)
    elif mode == "maint_db_dump_animalcsv":
        maint_db_dump_animalcsv(dbo)
    elif mode == "maint_db_dump_personcsv":
        maint_db_dump_personcsv(dbo)
    elif mode == "maint_db_dump_hsqldb":
        maint_db_dump_hsqldb(dbo)
    elif mode == "maint_db_install":
        maint_db_install(dbo)
    elif mode == "maint_db_reinstall":
        maint_db_reinstall(dbo)
    elif mode == "maint_db_reinstall_default_onlineforms":
        maint_db_reinstall_default_onlineforms(dbo)
    elif mode == "maint_db_reinstall_default_templates":
        maint_db_reinstall_default_templates(dbo)
    elif mode == "maint_db_replace_html_entities":
        maint_db_replace_html_entities(dbo)
    elif mode == "maint_db_reset":
        maint_db_reset(dbo)
    elif mode == "maint_db_update":
        maint_db_update(dbo)
    elif mode == "maint_db_delete_orphaned_media":
        maint_db_delete_orphaned_media(dbo)
    elif mode == "maint_deduplicate_people":
        maint_deduplicate_people(dbo)
    elif mode == "maint_disk_cache":
        maint_disk_cache(dbo)

    elapsed = time.time() - x
    al.info("end %s: elapsed %0.2f secs" % (mode, elapsed), "cron.run", dbo)