Skip to content

Instantly share code, notes, and snippets.

@mapledyne
Created July 1, 2015 16:18
Show Gist options
  • Save mapledyne/084d3a6daf0f8abda6aa to your computer and use it in GitHub Desktop.
Save mapledyne/084d3a6daf0f8abda6aa to your computer and use it in GitHub Desktop.
Will mark stale widgets in Dashing
$background-stale-color-1: #cc9999;
$background-stale-color-2: #333333;
$text-stale-color: #fff;
@-webkit-keyframes status-stale-background {
0% { background-color: $background-stale-color-1; }
50% { background-color: $background-stale-color-2; }
100% { background-color: $background-stale-color-1; }
}
.widget.status-stale {
background-color: $background-stale-color-1;
@include animation(status-stale-background, 2s, ease, infinite);
.icon-warning-sign {
display: inline-block;
}
.title, .more-info {
color: $text-stale-color;
}
}
require 'rubygems'
threshold = 7200
stale = "stale"
SCHEDULER.every '1m' do
widgets = Sinatra::Application.settings.history
total = 0
widgets.each do |key, value|
update_s = value.to_s.slice(value.to_s.index("updatedAt")+11..-1).tr('}','').strip
updated = update_s.to_i
now = Time.new().to_i
diff = now-updated
min = diff/60
if diff>threshold
puts "Stale widget (" + key.to_s + ") update time: " + min.to_s + " minutes ago."
send_event(key.to_s, { status: stale })
total = total + 1
end
end
puts "Stale widgets: " + total.to_s
send_event("stale_widgets", { value: total, current: total })
end
@itsonlym3
Copy link

could you enlighten me on how this is supposed to work b/c i'm having a heck of a time with it. once it is determined that the widget is stale , the next time the job runs it's updating the status of the widget and in turn the updatedAt is changing, so the widget is no longer stale, even though the job that initially updated the widget . am i missing something or is this the intent? from what i gathered from your blog. a widget would remain in a state of stale until the widget had been updated again by the job that originally put/pushed data to the widget.

@itsonlym3
Copy link

you sir are a genius! i have no idea what i was doing wrong, but i now have it working like a champ. going to let it run all night and see how things look in the morning. this is going to be a great tool for our IT Dept! thanks for the work you put into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment