Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve NewTask check; misc. style and code improvements
- Loading branch information
Showing
8 changed files
with
94 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
.bundle | ||
log | ||
config/env.rb | ||
*.db | ||
*.db-journal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,66 @@ | ||
# todo: | ||
# fetch from site (JSON GET) | ||
# fetch content from site (JSON GET) in parallel; fail if either email or content is missing | ||
# check that comment was added | ||
# unit test | ||
class NewTask < Check | ||
|
||
def default_params | ||
super.merge("wait_for" => 60) | ||
super.merge("period" => 30, "limit" => 600, "to" => "new@cohuman.com") | ||
end | ||
|
||
def subject | ||
"task #{param("key")}" | ||
end | ||
|
||
def run | ||
# todo: allow "run_in" to take a method name to be passed in to run!, so it can invoke it and then catch errors | ||
# todo: allow "run_again" to take a method name to be passed in to run!, so we don't need this switch | ||
if param("key") | ||
check_inbox | ||
else | ||
send_email | ||
end | ||
end | ||
|
||
def wait_for | ||
param("wait_for").to_i.seconds | ||
def period | ||
param("period").to_i | ||
end | ||
|
||
def send_email | ||
param("key", "#{Time.now.to_i}/#{rand(10000)}") | ||
OutgoingMessage.new( | ||
:to => "new@cohuman.com", | ||
:to => param("to"), | ||
:subject => subject, | ||
:body => subject | ||
).deliver | ||
run_again(wait_for.seconds) | ||
run_again(period.seconds) | ||
PENDING | ||
end | ||
|
||
def duration | ||
(Time.now - created_at).to_i | ||
end | ||
|
||
def limit | ||
param("limit").to_i | ||
end | ||
|
||
def check_inbox | ||
ok = false | ||
Receiver.new.scan do |message| | ||
if message.subject.include? param("key") | ||
ok = true | ||
message.delete | ||
self.reason = "received confirmation email after #{duration} seconds" | ||
return OK | ||
end | ||
end | ||
if ok | ||
OK | ||
|
||
self.reason = "did not receive confirmation email after #{duration} seconds" | ||
if duration >= limit | ||
return FAILED | ||
else | ||
self.reason = "did not receive confirmation email within #{wait_for} seconds" | ||
FAILED | ||
run_again(period.seconds) | ||
return PENDING | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
todo | ||
----- | ||
|
||
notifications via exceptional | ||
notifications via email (state change) | ||
stop/restart a check | ||
|
||
declared params, with description and default, per class | ||
inherited declared params | ||
typed params (e.g. int) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters