<commit_before>/*
 * Copyright (c) 2012 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package grails.plugins.crm.task

import grails.plugins.crm.security.CrmAccount

/**
 * Search for tasks with pending alarm that are due now and trigger alarms.
 */
class CrmTaskAlarmJob {

    static triggers = {
        simple name: 'crmTaskAlarm', startDelay: 90000, repeatInterval: 300000 // every five minutes
        //cron name: 'crmTaskAlarm', cronExpression: "0 0 6,9,12,15,18,21 * * ?" // every three hours daytime
    }

    def group = 'crmTask'

    def crmTaskService

    def execute() {
        for (due in crmTaskService.findDueAlarms()) {
            // select status from crm_account where id = (select account_id from crm_tenant where id = ?)
            def crmAccount = CrmAccount.find("from CrmAccount as a where a = (select account from CrmTenant as t where t.id = ?)", [due.tenantId])
            if(crmAccount?.active) {
                crmTaskService.triggerAlarm(due)
            }
        }
    }
}<commit_msg>Job must now be enabled with config crmTask.job.alarm.enabled<commit_after>/*
 * Copyright (c) 2012 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package grails.plugins.crm.task

import grails.plugins.crm.security.CrmAccount

/**
 * Search for tasks with pending alarm that are due now and trigger alarms.
 */
class CrmTaskAlarmJob {

    static triggers = {
        simple name: 'crmTaskAlarm', startDelay: 90000, repeatInterval: 300000 // every five minutes
    }

    def group = 'crmTask'

    def grailsApplication
    def crmTaskService

    def execute() {
        if(grailsApplication.config.crmTask.job.alarm.enabled) {
            for (due in crmTaskService.findDueAlarms()) {
                // select status from crm_account where id = (select account_id from crm_tenant where id = ?)
                def crmAccount = CrmAccount.find("from CrmAccount as a where a = (select account from CrmTenant as t where t.id = ?)", [due.tenantId])
                if(crmAccount?.active) {
                    crmTaskService.triggerAlarm(due)
                }
            }
        } else {
            log.debug "${getClass().getName()} is disabled because config [crmTask.job.alarm.enabled] is not true"
        }
    }
}
{'fraction_non_alphanumeric': 0.08947528055808311, 'fraction_numerical': 0.015165301789505611, 'mean_word_length': 2.7995391705069124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5562341', 'n_tokens_mistral': 967, 'n_tokens_neox': 914, 'n_words': 344}