day_planner 0.0.8 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 904c805d79424950a8099abbf95b0c6e2ae73647
4
- data.tar.gz: e764170c2aea3098683557d6fbc205d8b9ae1625
3
+ metadata.gz: 945c2843fc7f28b960f82bd71392ab2ef725ce0d
4
+ data.tar.gz: b716a7c571a211836e45bc0391612beee4ef6b2b
5
5
  SHA512:
6
- metadata.gz: 299536d558059bfc3c2be205cd5ffa02e3f4e615c69ce2650954f297bdf755f1655af306a9a003489c0b29a21b5d15759b5937700a66fa923f0be303be411b5d
7
- data.tar.gz: ab15735a5e24df16f4035864228fb1472450bb23ba3962053f86739b05dd0fd9cefbe117f13feabf2197600fda5e6de28dbfd4cd9cdfee5815d3bf91b099d069
6
+ metadata.gz: 803d6968fc5ae408ac6dfa209fd5a62b8494d72ea7c114da515ce70d6634816c79c4bc320c7ad428766331e5cd37eb9f2f4d3b08c6f26f7b619fb442cd3768d7
7
+ data.tar.gz: 2d302295627b1d2a1dd90a90dac2c72a6152e6e89f1a47aa22ba04f1032b2d2e3e3f9c4b61fb4d94ccf60ae50cde3675cb3df84bb671df7dfa5b5a589d8d9a98
data/README.md CHANGED
@@ -34,7 +34,7 @@ Obviously you only get those cute little time methods in Rails; otherwise, pass
34
34
 
35
35
  The tasks in the schedule will each be performed on startup and then thereafter according to their stated intervals.
36
36
 
37
- I'm not doing a whole damn ton to protect you from tasks that throw errors, but there is a begin/rescue/end up in there at some point. I definitely am not protecting you from a process that just won't end or anything like that. Given that each task is run in its own thread, you have some faint assurance that they are occuring at whatever interval you specify plus a very small amount of overhead.
37
+ I'm not doing a whole damn ton to protect you from tasks that throw errors, but there is a begin/rescue/end up in there at some point. I definitely am not protecting you from a process that just won't end or anything like that. Remember that your interval is really the minimum possible time between instances of the task being performed, as it does not spawn a new thread for that purpose.
38
38
 
39
39
  By default, DayPlanner checks for tasks to be performed once per minute. You have the power to change this:
40
40
 
@@ -48,23 +48,36 @@ Note that if you try to schedule a task with an interval shorter than DayPlanner
48
48
 
49
49
  Specify your preferred interval (and whatever other goodies may be waiting in the pipeline) in config/day_planner_tasks.rb. Note that you probably won't manage to precede that first minute-long wait. I may default to a shorter value in the future. I dunno. Don't pressure me.
50
50
 
51
- ### Non-Rails uses
51
+ ### Other options
52
52
 
53
- I sort of think it might work without Rails, keeping in mind the various aforementioned caveats? I'm not really sure. If it totally doesn't, I'd appreciate feedback.
53
+ #### name
54
54
 
55
55
  You can name a task thusly:
56
+
56
57
  DayPlanner.schedule(every: 2.minutes, name: "my task") do
57
- MyClass.my_class_method
58
+ MyClass.my_class_method
58
59
  end
59
60
 
60
61
  If you do, you can find the task later:
61
62
  DayPlanner.find_task("my task")
62
63
 
64
+ #### environment
65
+
66
+ If you're using Rails, you can include environment in your options hash, setting the value to the Rails environment in which you'd like the task executed. For example:
67
+
68
+ DayPlanner.schedule(every: 1.hour, name: "occasional task", environment: "production") do
69
+ # I run every hour, but only if you're using Rails and in production.
70
+ end
71
+
63
72
  To cancel a task, you can either call the task's "destroy" method, or call a class method on DayPlanner:
64
73
  DayPlanner.cancel(task)
65
74
 
66
75
  You can either pass a name, if you named the task, or the task object.
67
76
 
77
+ ### Non-Rails uses
78
+
79
+ I sort of think it might work without Rails, keeping in mind the various aforementioned caveats? I'm not really sure. If it totally doesn't, I'd appreciate feedback.
80
+
68
81
  ## Contributing
69
82
 
70
83
  1. Fork it
@@ -22,7 +22,7 @@ module DayPlanner
22
22
  def activate
23
23
  @@master.kill if defined?(@@master)
24
24
 
25
- if Rails && Rails.logger
25
+ if defined?(Rails) && Rails.logger
26
26
  Rails.logger.info("DayPlanner activated.")
27
27
  else
28
28
  puts "DayPlanner activated."
@@ -65,7 +65,7 @@ module DayPlanner
65
65
  begin
66
66
  t.perform
67
67
  rescue => e
68
- if Rails && Rails.logger
68
+ if defined?(Rails) && Rails.logger
69
69
  Rails.logger.error("DayPlanner: Scheduled task threw an error! Behave yourselves!\n#{e.inspect}")
70
70
  else
71
71
  puts "DayPlanner: Scheduled task threw an error! Behave yourselves!\n#{e.inspect}"
@@ -80,12 +80,26 @@ module DayPlanner
80
80
  attr_reader :last_executed, :interval
81
81
 
82
82
  def perform
83
- @last_executed = Time.now
83
+ if @environment.nil? || (defined?(Rails) && defined?(Rails.environment) && Rails.environment == @environment)
84
+ @last_executed = Time.now
84
85
 
85
- @thread.kill if defined?(@thread)
86
-
87
- @thread = Thread.new do
88
86
  @task.call
87
+ else
88
+ log_info = "DayPlanner: "
89
+
90
+ if @name
91
+ log_info += "Skipping task '#{@name}'"
92
+ else
93
+ log_info += "Skipping a task"
94
+ end
95
+
96
+ log_info += " because it's set for environment '#{@environment}'."
97
+
98
+ if defined?(Rails) && Rails.logger
99
+ Rails.logger.info(log_info)
100
+ else
101
+ puts log_info
102
+ end
89
103
  end
90
104
  end
91
105
 
@@ -112,6 +126,8 @@ module DayPlanner
112
126
  end
113
127
  end
114
128
 
129
+ @environment = options.delete(:environment) if options[:environment]
130
+
115
131
  @task = block
116
132
 
117
133
  DayPlanner.tasks.push(self)
@@ -119,7 +135,7 @@ module DayPlanner
119
135
  log_info += ": '#{@name}'" unless @name.nil?
120
136
  log_info += " with an execution interval of #{@interval.to_i} seconds."
121
137
 
122
- if Rails && Rails.logger
138
+ if defined?(Rails) && Rails.logger
123
139
  Rails.logger.info(log_info)
124
140
  else
125
141
  puts log_info
@@ -128,7 +144,7 @@ module DayPlanner
128
144
  begin
129
145
  perform
130
146
  rescue => e
131
- if Rails && Rails.logger
147
+ if defined?(Rails) && Rails.logger
132
148
  Rails.logger.error("DayPlanner: Task caused error on first performance. There's no second chance for a good first impression!\n#{e.inspect}")
133
149
  else
134
150
  puts "DayPlanner: Task caused error on first performance. There's no second chance for a good first impression!\n#{e.inspect}"
@@ -1,7 +1,7 @@
1
1
  module DayPlanner
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- TINY = 8
4
+ TINY = 11
5
5
  BUILD = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, TINY, BUILD].compact.join(".")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: day_planner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damon Siefert