MCPcopy Create free account
hub / github.com/annmuor/jnode / Schedule

Class Schedule

jnode-core/src/jnode/dto/Schedule.java:36–154  ·  view source on GitHub ↗

Планировщик (жалкая замена cron :-) ) @author Manjago

Source from the content-addressed store, hash-verified

34 * @author Manjago
35 */
36@DatabaseTable(tableName = "schedule")
37public class Schedule {
38 private static final ConcurrentDateFormatAccess DATE_DAY_FORMAT = new ConcurrentDateFormatAccess("MMMM dd yyyy");
39 private static final ConcurrentDateFormatAccess DATE_HOUR_FORMAT = new ConcurrentDateFormatAccess("MMMM dd yyyy HH");
40 @DatabaseField(columnName = "id", generatedId = true)
41 private Long id;
42 @DatabaseField(dataType = DataType.ENUM_STRING, canBeNull = false, columnName = "type", defaultValue = "DAILY")
43 private Type type;
44 @DatabaseField(columnName = "details", defaultValue = "0")
45 private Integer details;
46 @DatabaseField(columnName = "jscript_id", foreign = true, canBeNull = false, uniqueIndexName = "lsched_idx")
47 private Jscript jscript;
48 @DatabaseField(columnName = "lastRunDate", canBeNull = true, dataType = DataType.DATE)
49 private Date lastRunDate;
50
51 private static boolean isSameDay(Date date1, Date date2) {
52 return !(date1 == null || date2 == null) && DATE_DAY_FORMAT.format(date1).equals(DATE_DAY_FORMAT.format(date2));
53 }
54
55 private static boolean isSameHour(Date date1, Date date2) {
56 return !(date1 == null || date2 == null) && DATE_HOUR_FORMAT.format(date1).equals(DATE_HOUR_FORMAT.format(date2));
57 }
58
59 public Long getId() {
60 return id;
61 }
62
63 public void setId(Long id) {
64 this.id = id;
65 }
66
67 public Date getLastRunDate() {
68 return lastRunDate;
69 }
70
71 public void setLastRunDate(Date lastRunDate) {
72 this.lastRunDate = lastRunDate;
73 }
74
75 public boolean isNeedExec(Calendar calendar) {
76
77 if (calendar == null || getType() == null || getDetails() == null) {
78 return false;
79 }
80
81 switch (getType()) {
82 case HOURLY:
83 if (isSameHour(getLastRunDate(), new Date())) {
84 return false;
85 }
86 break;
87 default:
88 if (isSameDay(getLastRunDate(), new Date())) {
89 return false;
90 }
91 break;
92 }
93

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected