public void scheduleJob()

in src/main/java/com/aws/iot/edgeconnectorforkvs/scheduler/JobScheduler.java [83:123]


    public void scheduleJob(Constants.JobType jobType, String streamName, String startTimeExpr,
                            long jobDurationInMins) {
        try {
            // hardcode seconds part to 0
            startTimeExpr = Integer.toString(Constants.SCHEDULER_SECONDS_BOUNDARY) + " " + startTimeExpr;
            boolean valid = verifyCron(startTimeExpr, jobDurationInMins);
            if (!valid) {
                final String errorMessage = String.format("Error: Invalid Start Time Expression and Job Duration." +
                                "Job Type: %s, Stream Name: %s, StartTime Expr: %s, Job Duration: %d mins." +
                                "Job not scheduled.", jobType.name(), streamName,
                        startTimeExpr, jobDurationInMins);
                log.error(errorMessage);
                throw new EdgeConnectorForKVSException(errorMessage);
            }
            Scheduler sched = null;
            sched = this.schedulerFactory.getScheduler();
            // seconds, minute, hour, day-of-month, month, day-of-week, year(optional)
            log.info("Start Job Cron Expression: " + startTimeExpr);
            JobDetail jobDetail = newJob(StartJob.class)
                    .withIdentity(streamName, jobType.name() + "_START")
                    .build();
            CronTrigger startTrigger = newTrigger()
                    .withIdentity(streamName + "-" + jobDetail.getKey(), jobType.name())
                    .withSchedule(cronSchedule(startTimeExpr))
                    .build();
            JobDataMap jobDataMap = jobDetail.getJobDataMap();
            jobDataMap.put(Constants.JOB_TYPE_KEY, jobType);
            jobDataMap.put(Constants.JOB_DURATION_IN_MINS_KEY, jobDurationInMins);
            jobDataMap.put(Constants.JOB_STREAM_NAME_KEY, streamName);
            jobDataMap.put(Constants.JOB_CALLBACK_INSTANCE, schedulerCallback);
            Date ft = sched.scheduleJob(jobDetail, startTrigger);
            log.info(jobDetail.getKey() + " has been scheduled to run at: " + ft + " and repeat based on expression: "
                    + startTrigger.getCronExpression());
        } catch (ParseException | SchedulerException ex) {
            final String errorMessage = String.format("Could not schedule job for Job Type: %s, Stream Name: %s, " +
                            "StartTime Expr: %s, Job Duration: %d mins. %s", jobType.name(), streamName,
                    startTimeExpr, jobDurationInMins, ex.getMessage());
            log.error(errorMessage);
            throw new EdgeConnectorForKVSException(errorMessage, ex);
        }
    }