2017-12-14 07:52:01 -07:00
|
|
|
|
2018-08-18 10:06:49 -06:00
|
|
|
def check_for_digests
|
|
|
|
Log
|
|
|
|
.where(sent_at: nil, created_at: 1.day.ago...Time.now)
|
|
|
|
.where(Log::IS_EMAIL_ISH)
|
|
|
|
.where
|
|
|
|
.not(Log::IS_FATAL_EMAIL)
|
|
|
|
.pluck(:device_id)
|
|
|
|
.uniq
|
|
|
|
.map do |id|
|
|
|
|
device = Device.find(id)
|
|
|
|
puts "Sending log digest to device \##{id} (#{device.name})"
|
|
|
|
LogDeliveryMailer.log_digest(device).deliver
|
|
|
|
end
|
2018-10-03 08:46:25 -06:00
|
|
|
sleep 10.minutes
|
2018-08-18 10:06:49 -06:00
|
|
|
end
|
|
|
|
|
2018-10-03 12:07:22 -06:00
|
|
|
def hard_reset_api
|
|
|
|
sh "sudo docker stop $(sudo docker ps -a -q)"
|
|
|
|
sh "sudo docker rm $(sudo docker ps -a -q)"
|
2018-10-04 09:57:54 -06:00
|
|
|
sh "sudo rm -rf docker_volumes/"
|
2018-10-03 12:07:22 -06:00
|
|
|
rescue => exception
|
|
|
|
puts exception.message
|
|
|
|
puts "Reset failed. Was there nothing to destroy?"
|
|
|
|
end
|
|
|
|
|
|
|
|
def rebuild_deps
|
|
|
|
sh "sudo docker-compose run web bundle install"
|
|
|
|
sh "sudo docker-compose run web npm install"
|
|
|
|
sh "sudo docker-compose run web bundle exec rails db:setup"
|
|
|
|
sh "sudo docker-compose run web rake keys:generate"
|
|
|
|
sh "sudo docker-compose run web npm run build"
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_typed?(word)
|
|
|
|
STDOUT.flush
|
|
|
|
STDIN.gets.chomp.downcase.include?(word.downcase)
|
|
|
|
end
|
|
|
|
|
2017-10-10 16:27:28 -06:00
|
|
|
namespace :api do
|
2018-08-18 10:06:49 -06:00
|
|
|
desc "Runs pending email digests. "\
|
|
|
|
"Use the `FOREVER` ENV var to continually check."
|
2018-08-17 07:10:32 -06:00
|
|
|
task log_digest: :environment do
|
2019-01-24 07:07:11 -07:00
|
|
|
puts "Running log digest loop..."
|
2018-08-18 10:06:49 -06:00
|
|
|
ENV["FOREVER"] ? loop { check_for_digests } : check_for_digests
|
2018-08-17 07:10:32 -06:00
|
|
|
end
|
|
|
|
|
2018-10-02 19:08:24 -06:00
|
|
|
desc "Run Rails _ONLY_. No Webpack."
|
|
|
|
task only: :environment do
|
|
|
|
sh "sudo docker-compose up --scale webpack=0"
|
|
|
|
end
|
|
|
|
|
2019-01-29 09:45:50 -07:00
|
|
|
desc "Serve javascript assets (via Parcel bundler)"
|
|
|
|
task serve_assets: :environment do
|
2019-01-29 14:54:00 -07:00
|
|
|
css = DashboardController::CSS_INPUTS.values
|
|
|
|
js = DashboardController::JS_INPUTS.values
|
2019-01-29 09:45:50 -07:00
|
|
|
assets = (js + css)
|
|
|
|
.sort
|
|
|
|
.uniq
|
|
|
|
.map { |x| "webpack" + x }
|
|
|
|
.join(" ")
|
2019-01-29 14:54:00 -07:00
|
|
|
|
|
|
|
cli = [
|
2019-01-29 09:45:50 -07:00
|
|
|
"node_modules/parcel-bundler/bin/cli.js",
|
2019-01-29 14:54:00 -07:00
|
|
|
"build",
|
2019-01-29 09:45:50 -07:00
|
|
|
assets,
|
|
|
|
"--out-dir public/dist",
|
2019-01-29 14:54:00 -07:00
|
|
|
"--public-url /dist",
|
|
|
|
# "--hmr-hostname #{ENV.fetch("API_HOST")}",
|
|
|
|
# "--hmr-port 3808",
|
|
|
|
"--bundle-node-modules",
|
2019-01-29 09:45:50 -07:00
|
|
|
"--log-level 5",
|
|
|
|
].join(" ")
|
|
|
|
# /dist/front_page/index.jd
|
|
|
|
# /dist/front_page/index.js
|
|
|
|
puts "=== Running: \n#{cli}"
|
|
|
|
sh cli
|
|
|
|
end
|
|
|
|
|
2018-10-03 12:07:22 -06:00
|
|
|
desc "Reset _everything_, including your database"
|
|
|
|
task :reset do
|
2018-10-04 09:57:54 -06:00
|
|
|
puts "This is going to destroy _ALL_ of your local Farmbot SQL data and "\
|
|
|
|
"configs. Type 'destroy' to continue, enter to abort."
|
2018-10-03 12:07:22 -06:00
|
|
|
if user_typed?("destroy")
|
|
|
|
hard_reset_api
|
2018-10-04 09:57:54 -06:00
|
|
|
puts "Done. Type 'build' to re-install dependencies, enter to abort."
|
2018-10-03 12:07:22 -06:00
|
|
|
rebuild_deps if user_typed?("build")
|
|
|
|
end
|
|
|
|
end
|
2018-11-15 10:13:11 -07:00
|
|
|
|
|
|
|
VERSION = "tag_name"
|
|
|
|
TIMESTAMP = "created_at"
|
|
|
|
|
|
|
|
desc "Update GlobalConfig to deprecate old FBOS versions"
|
|
|
|
task deprecate: :environment do
|
|
|
|
# Get current version
|
2018-11-15 10:36:07 -07:00
|
|
|
version_str = GlobalConfig.dump.fetch("FBOS_END_OF_LIFE_VERSION")
|
2018-11-15 10:13:11 -07:00
|
|
|
# Convert it to Gem::Version for easy comparisons (>, <, ==, etc)
|
|
|
|
current_version = Gem::Version::new(version_str)
|
|
|
|
# 60 days is the current policy.
|
|
|
|
cutoff = 60.days.ago
|
|
|
|
# Download release data from github
|
|
|
|
stringio = open("https://api.github.com/repos/farmbot/farmbot_os/releases")
|
|
|
|
string = stringio.read
|
|
|
|
data = JSON
|
|
|
|
.parse(string)
|
|
|
|
.map { |x| x.slice(VERSION, TIMESTAMP) } # Only grab keys that matter
|
|
|
|
.reject { |x| x.fetch(VERSION).include?("-") } # Remove RC/Beta releases
|
|
|
|
.map do |x|
|
|
|
|
# Convert string-y version/timestamps to Real ObjectsTM
|
|
|
|
version = Gem::Version::new(x.fetch(VERSION).gsub("v", ""))
|
|
|
|
time = DateTime.parse(x.fetch(TIMESTAMP))
|
|
|
|
Pair.new(version, time)
|
|
|
|
end
|
|
|
|
.select do |pair|
|
|
|
|
# Grab versions that are > current version and outside of cutoff window
|
|
|
|
(pair.head > current_version) && (pair.tail < cutoff)
|
|
|
|
end
|
|
|
|
.sort_by { |p| p.tail } # Sort by release date
|
|
|
|
.last(2) # Grab 2 latest versions (closest to cuttof)
|
|
|
|
.first # Give 'em some leeway, grabbing the 2nd most outdated version.
|
|
|
|
.try(:head) # We might already be up-to-date?
|
|
|
|
if data # ...or not
|
|
|
|
puts "Setting new support target to #{data.to_s}"
|
|
|
|
GlobalConfig # Set the new oldest support version.
|
2018-11-15 10:36:07 -07:00
|
|
|
.find_by(key: "FBOS_END_OF_LIFE_VERSION")
|
2018-11-15 13:54:33 -07:00
|
|
|
.update_attributes!(value: data.to_s)
|
2018-11-15 10:13:11 -07:00
|
|
|
end
|
|
|
|
end
|
2017-10-10 16:27:28 -06:00
|
|
|
end
|