Fix email issue reported by @ConnorRigby
parent
521938e29c
commit
3dedf27c62
|
@ -5,15 +5,14 @@ module Api
|
|||
def create
|
||||
case raw_json
|
||||
when Array
|
||||
log_params = raw_json
|
||||
.last(current_device.max_log_count)
|
||||
.map { |i| new_log(i) }
|
||||
.select { |i| i.success? } # Ignore rejects
|
||||
.map { |i| i.result }
|
||||
.select { |i| i.meta["type"] != "fun"} # Don't save jokes
|
||||
.map { |i| i.as_json }
|
||||
# .tap { |i| Log.create(i) }
|
||||
logs = Log.create(log_params).tap { |i| maybe_deliver(i) }
|
||||
logs = Log
|
||||
.create(raw_json.last(current_device.max_log_count)
|
||||
.map { |i| new_log(i) }
|
||||
.select { |i| i.success? } # <= Ignore rejects
|
||||
.map { |i| i.result } # Don't save jokes:
|
||||
.select { |i| i.meta["type"] != "fun"}
|
||||
.map { |i| i.as_json })
|
||||
.tap { |i| maybe_deliver(i) }
|
||||
render json: logs
|
||||
when Hash
|
||||
outcome = new_log(raw_json)
|
||||
|
|
|
@ -9,10 +9,12 @@ class LogDeliveryMailer < ApplicationMailer
|
|||
"Device #{device.id} is sending too many emails!!! (> 20 / hr)"
|
||||
end
|
||||
ld = LogDispatch.where(sent_at: nil, device: device)
|
||||
logs = Log.find(ld.pluck(:log_id))
|
||||
@emails = device.users.pluck(:email)
|
||||
@messages = logs.map(&:message)
|
||||
mail(to: @emails, subject: '🌱 New message from FarmBot!')
|
||||
ld.update_all(sent_at: Time.now)
|
||||
if(ld.any?)
|
||||
logs = Log.find(ld.pluck(:log_id))
|
||||
@emails = device.users.pluck(:email)
|
||||
@messages = logs.map(&:message)
|
||||
mail(to: @emails, subject: '🌱 New message from FarmBot!')
|
||||
ld.update_all(sent_at: Time.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
[{
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "warn"
|
||||
},
|
||||
"message": "FIXME failed to install first party farmwares: %RuntimeError{message: \"Could not sync Elixir.Farmbot.Farmware.Installer.Repository.Farmbot is already synced up!\"}",
|
||||
"created_at": 1495820256,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "info"
|
||||
},
|
||||
"message": "FIXME is installing first party Farmwares.",
|
||||
"created_at": 1495820255,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "info"
|
||||
},
|
||||
"message": "FIXME ntp: :ok",
|
||||
"created_at": 1495820255,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "warn"
|
||||
},
|
||||
"message": "No serial handler yet, waiting...",
|
||||
"created_at": 23,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "info"
|
||||
},
|
||||
"message": "FIXME trying to set time (try 0)",
|
||||
"created_at": 22,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "info"
|
||||
},
|
||||
"message": "FIXME is getting time from NTP.",
|
||||
"created_at": 22,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "info"
|
||||
},
|
||||
"message": "FIXME starting ntp client.",
|
||||
"created_at": 22,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "success"
|
||||
},
|
||||
"message": "FIXME connection test complete",
|
||||
"created_at": 22,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "busy"
|
||||
},
|
||||
"message": "FIXME doing connection test...",
|
||||
"created_at": 21,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "warn"
|
||||
},
|
||||
"message": "No serial handler yet, waiting...",
|
||||
"created_at": 18,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "info"
|
||||
},
|
||||
"message": "FIXME is waiting for linux and network and what not.",
|
||||
"created_at": 16,
|
||||
"channels": []
|
||||
}, {
|
||||
"meta": {
|
||||
"z": 0,
|
||||
"y": 0,
|
||||
"x": 0,
|
||||
"type": "info"
|
||||
},
|
||||
"message": "FIXME Configurator init!",
|
||||
"created_at": 15,
|
||||
"channels": []
|
||||
}]
|
|
@ -1,4 +1,5 @@
|
|||
require 'spec_helper'
|
||||
JSON_EXAMPLE = File.read("spec/controllers/api/logs/connor_fixture.json")
|
||||
|
||||
describe Api::LogsController do
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
@ -128,5 +129,16 @@ describe Api::LogsController do
|
|||
end
|
||||
|
||||
it "batches multiple messages"
|
||||
|
||||
it "handles bug that Connor reported" do
|
||||
sign_in user
|
||||
empty_mail_bag
|
||||
Log.destroy_all
|
||||
LogDispatch.destroy_all
|
||||
post :create,
|
||||
body: JSON_EXAMPLE,
|
||||
params: {format: :json}
|
||||
expect(last_email).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue