refactor methods to calculate next build time
This commit is contained in:
parent
3fa9c09c0c
commit
8a6f4066ae
|
@ -5,80 +5,42 @@ module Travis::API::V3
|
||||||
|
|
||||||
def next_enqueuing
|
def next_enqueuing
|
||||||
|
|
||||||
if (disable_by_build) && (last_non_cron_build_date > last_planned_time)
|
if (disable_by_build) && (last_non_cron_build_date > plannedTime(-1))
|
||||||
return after_next_planned_time
|
return plannedTime(1)
|
||||||
elsif last_cron_build_date >= last_planned_time
|
elsif last_cron_build_date >= plannedTime(-1)
|
||||||
return next_planned_time
|
return plannedTime(0)
|
||||||
else
|
else
|
||||||
return Time.now
|
return Time.now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def next_planned_time
|
def plannedTime(in_builds = 0) # 0 equals next build, 1 after next build, -1 last build, ...
|
||||||
now = DateTime.now
|
now = DateTime.now
|
||||||
created = DateTime.new(created_at.year, created_at.month, created_at.day, created_at.hour)
|
created = DateTime.new(created_at.year, created_at.month, created_at.day, created_at.hour)
|
||||||
case interval
|
case interval
|
||||||
when 'daily'
|
when 'daily'
|
||||||
build_today = DateTime.new(now.year, now.month, now.day, created_at.hour)
|
build_today = DateTime.new(now.year, now.month, now.day, created_at.hour)
|
||||||
if now > build_today
|
if now > build_today
|
||||||
return build_today + 1
|
return build_today + 1 + in_builds
|
||||||
else
|
else
|
||||||
return build_today
|
return build_today + in_builds
|
||||||
end
|
end
|
||||||
when 'weekly'
|
when 'weekly'
|
||||||
build_today = DateTime.new(now.year, now.month, now.day, created_at.hour)
|
build_today = DateTime.new(now.year, now.month, now.day, created_at.hour)
|
||||||
in_days = (created_at.wday - now.wday) % 7
|
in_days = (created_at.wday - now.wday) % 7
|
||||||
next_time = build_today + in_days
|
next_time = build_today + in_days
|
||||||
if now > next_time
|
if now > next_time
|
||||||
return build_today + 7
|
return build_today + 7 * (1 + in_builds)
|
||||||
else
|
else
|
||||||
return next_time
|
return next_time + 7 * in_builds
|
||||||
end
|
end
|
||||||
when 'monthly'
|
when 'monthly'
|
||||||
month_since_creation = (now.year*12+now.month) - (created_at.year*12+created_at.month)
|
month_since_creation = (now.year*12+now.month) - (created_at.year*12+created_at.month)
|
||||||
this_month = created >> month_since_creation
|
this_month = created >> month_since_creation
|
||||||
if now > this_month
|
if now > this_month
|
||||||
return created >> (month_since_creation+1)
|
return created >> (month_since_creation + 1 + in_builds)
|
||||||
else
|
else
|
||||||
return this_month
|
return created >> (month_since_creation + in_builds)
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_planned_time
|
|
||||||
now = DateTime.now
|
|
||||||
created = DateTime.new(created_at.year, created_at.month, created_at.day, created_at.hour)
|
|
||||||
case interval
|
|
||||||
when 'daily'
|
|
||||||
return next_planned_time - 1
|
|
||||||
when 'weekly'
|
|
||||||
return next_planned_time - 7
|
|
||||||
when 'monthly'
|
|
||||||
month_since_creation = (now.year*12+now.month) - (created_at.year*12+created_at.month)
|
|
||||||
this_month = created >> month_since_creation
|
|
||||||
if now > this_month
|
|
||||||
return this_month
|
|
||||||
else
|
|
||||||
return created >> (month_since_creation-1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_next_planned_time
|
|
||||||
now = DateTime.now
|
|
||||||
created = DateTime.new(created_at.year, created_at.month, created_at.day, created_at.hour)
|
|
||||||
case interval
|
|
||||||
when 'daily'
|
|
||||||
return next_planned_time + 1
|
|
||||||
when 'weekly'
|
|
||||||
return next_planned_time + 7
|
|
||||||
when 'monthly'
|
|
||||||
month_since_creation = (now.year*12+now.month) - (created_at.year*12+created_at.month)
|
|
||||||
this_month = created >> month_since_creation
|
|
||||||
if now > this_month
|
|
||||||
return created >> (month_since_creation+2)
|
|
||||||
else
|
|
||||||
return created >> (month_since_creation+1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user