001/* 002 * Stallion Core: A Modern Web Framework 003 * 004 * Copyright (C) 2015 - 2016 Stallion Software LLC. 005 * 006 * This program is free software: you can redistribute it and/or modify it under the terms of the 007 * GNU General Public License as published by the Free Software Foundation, either version 2 of 008 * the License, or (at your option) any later version. This program is distributed in the hope that 009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 011 * License for more details. You should have received a copy of the GNU General Public License 012 * along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. 013 * 014 * 015 * 016 */ 017 018package io.stallion.jobs; 019 020import io.stallion.plugins.PluginRegistry; 021 022import java.time.ZonedDateTime; 023 024public class JobDefinition { 025 private String name; 026 private Schedule schedule; 027 private int alertThresholdMinutes = 75; 028 private String className; 029 private Class<? extends Job> jobClass; 030 031 032 033 public String getName() { 034 return name; 035 } 036 037 public JobDefinition setName(String name) { 038 this.name = name; 039 return this; 040 } 041 042 public Schedule getSchedule() { 043 return schedule; 044 } 045 046 public JobDefinition setSchedule(Schedule schedule) { 047 this.schedule = schedule; 048 return this; 049 } 050 051 /** 052 * The number of minutes after which the jobs was supposed to run at which 053 * we return errors in the healthcheck endpoint because the job has not finished 054 * running. Default to 75 minutes. 055 * 056 * @return 057 */ 058 public int getAlertThresholdMinutes() { 059 return alertThresholdMinutes; 060 } 061 062 public JobDefinition setAlertThresholdMinutes(int alertThresholdMinutes) { 063 this.alertThresholdMinutes = alertThresholdMinutes; 064 return this; 065 } 066 067 public String getJobClassName() { 068 return className; 069 } 070 071 public JobDefinition setJobClassName(String className) { 072 this.className = className; 073 return this; 074 } 075 076 public JobDefinition setJobClass(Class<? extends Job> cls) { 077 setJobClassName(cls.getCanonicalName()); 078 this.jobClass = cls; 079 return this; 080 } 081 082 083 084 public Class<? extends Job> getJobClass() { 085 if (jobClass != null) { 086 return jobClass; 087 } 088 try { 089 return (Class<Job>)PluginRegistry.instance().getClassLoader().loadClass(getJobClassName()); 090 } catch (ClassNotFoundException e) { 091 throw new RuntimeException(e); 092 } 093 } 094 095 096 097}