<commit_before><commit_msg>[quartz] implementação do schedule service<commit_after>package br.net.mirante.singular.flow.schedule.quartz;

import java.util.ResourceBundle;

import org.quartz.Scheduler;
import org.quartz.Trigger;

import br.net.mirante.singular.flow.schedule.IScheduleService;
import br.net.mirante.singular.flow.schedule.IScheduledJob;

import com.google.common.base.Throwables;

public class QuartzScheduleService implements IScheduleService {

    private final QuartzSchedulerFactory quartzSchedulerFactory;

    public QuartzScheduleService() {
        quartzSchedulerFactory = new QuartzSchedulerFactory();
        quartzSchedulerFactory.setSchedulerName("SingularFlowScheduler");
        quartzSchedulerFactory.setConfigLocation(ResourceBundle.getBundle("quartz"));
        try {
            quartzSchedulerFactory.initialize();
            quartzSchedulerFactory.start();
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }

    @Override
    public void schedule(IScheduledJob scheduledJob) {
        try {
            Trigger trigger = QuartzTriggerFactory.newTrigger().forJob(scheduledJob::run).withScheduleData(scheduledJob.getScheduleData()).build();

            getScheduler().scheduleJob(trigger);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }

    public Scheduler getScheduler() {
        return quartzSchedulerFactory.getScheduler();
    }
}
{'fraction_non_alphanumeric': 0.09252912954078135, 'fraction_numerical': 0.0, 'mean_word_length': 3.6202531645569622, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3962204', 'n_tokens_mistral': 411, 'n_tokens_neox': 388, 'n_words': 62}