day_planner 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -7
- data/lib/day_planner/base.rb +18 -4
- data/lib/day_planner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd170c0b68eb8d2b6f5500d091e48f54f84ed18b
|
4
|
+
data.tar.gz: 8d60689a518fb2eef34d02bd69cf428cc2f2ca98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c5afc19ceb951b1d4a110b7c2f4315a4b30e416bbf7ca0c984f6a3e5de0a184c4dec0acc5fe2d64697013fa74f144ebe1369140b3ca03f39c58108df3bff97c
|
7
|
+
data.tar.gz: 7806772039f3eaeacee8eb60b6e1d261fbca268fb8a482815b2de4016c548b40e45d52c4bfd104a23af432b38a195a96032155ee799a2759a1c35cf39aefdc8c
|
data/README.md
CHANGED
@@ -24,13 +24,29 @@ If you're using Rails, it'll expect to find a file listing scheduled tasks in 'c
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
27
|
+
### Rails
|
28
|
+
|
29
|
+
Create a file called config/scheduled_tasks.rb. Put tasks in it like this:
|
28
30
|
|
29
31
|
DayPlanner.schedule(every: 2.minutes) do
|
30
32
|
MyClass.my_class_method
|
31
33
|
end
|
32
34
|
|
33
|
-
|
35
|
+
This file will be read in and its tasks will be added to the schedule automatically.
|
36
|
+
|
37
|
+
### If you're not using Rails
|
38
|
+
|
39
|
+
I don't really know if it'll work. I haven't tried.
|
40
|
+
|
41
|
+
You will have to create a scheduled tasks file, somewhere. Use the same format, but obviously you won't have those cute little Rails-y time methods. You'll want to include this at the bottom:
|
42
|
+
|
43
|
+
DayPlanner.activate
|
44
|
+
|
45
|
+
It's only activated automatically in Rails.
|
46
|
+
|
47
|
+
I have not tested it outside of Rails and it may not work at all but ideally I'd prefer that it did. If you can give me feedback, I'd be much obliged.
|
48
|
+
|
49
|
+
### Either way
|
34
50
|
|
35
51
|
The tasks in the schedule will each be performed on startup and then thereafter according to their stated intervals.
|
36
52
|
|
@@ -44,7 +60,7 @@ Or, like
|
|
44
60
|
|
45
61
|
DayPlanner.interval = 5
|
46
62
|
|
47
|
-
Note that if you try to schedule a task with an interval shorter than DayPlanner's interval, it'll complain and fail. If you shorten DayPlanner's interval to less than that of one of its tasks, it'll complain but not fail.
|
63
|
+
Note that if you try to schedule a task with an interval shorter than DayPlanner's interval, it'll complain and fail. If you shorten DayPlanner's interval to less than that of one of its tasks, it'll complain but not fail. The task obviously will only run at scheduler thread's intervals. Use your best judgment.
|
48
64
|
|
49
65
|
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
66
|
|
@@ -74,10 +90,6 @@ To cancel a task, you can either call the task's "destroy" method, or call a cla
|
|
74
90
|
|
75
91
|
You can either pass a name, if you named the task, or the task object.
|
76
92
|
|
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
|
-
|
81
93
|
## Contributing
|
82
94
|
|
83
95
|
1. Fork it
|
data/lib/day_planner/base.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module DayPlanner
|
2
2
|
@@tasks = []
|
3
3
|
@@named_tasks = {}
|
4
|
+
@@status = "stopped"
|
5
|
+
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
config.after_initialize do
|
8
|
+
require File.expand_path('config/scheduled_tasks')
|
9
|
+
DayPlanner.activate
|
10
|
+
end
|
11
|
+
end
|
4
12
|
|
5
13
|
class << self
|
6
14
|
def tasks
|
@@ -18,9 +26,19 @@ module DayPlanner
|
|
18
26
|
raise ArgumentError, "DayPlanner couldn't find this task" if task.nil? || !task.is_a?(DayPlanner::Task)
|
19
27
|
task.destroy
|
20
28
|
end
|
29
|
+
|
30
|
+
def status
|
31
|
+
@@status
|
32
|
+
end
|
33
|
+
|
34
|
+
def deactivate
|
35
|
+
@@master.kill if defined?(@@master)
|
36
|
+
@@status = "stopped"
|
37
|
+
end
|
21
38
|
|
22
39
|
def activate
|
23
40
|
@@master.kill if defined?(@@master)
|
41
|
+
@@status = "running"
|
24
42
|
|
25
43
|
if defined?(Rails) && Rails.logger
|
26
44
|
Rails.logger.info("DayPlanner activated.")
|
@@ -153,7 +171,3 @@ module DayPlanner
|
|
153
171
|
end
|
154
172
|
end
|
155
173
|
end
|
156
|
-
|
157
|
-
require File.expand_path('config/scheduled_tasks') if defined?(Rails)
|
158
|
-
|
159
|
-
DayPlanner.activate
|
data/lib/day_planner/version.rb
CHANGED