asynr 1.0.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -14
- data/README.md +72 -79
- data/asynr.gemspec +7 -10
- data/lib/asynr.rb +5 -7
- data/lib/asynr/core.rb +54 -38
- data/lib/asynr/job.rb +55 -27
- data/lib/asynr/scheduler.rb +100 -0
- data/lib/asynr/version.rb +1 -1
- metadata +12 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be2122555ff23eaa2ab0c58a772e456a6a2348dd4918247be899032fd005e45c
|
4
|
+
data.tar.gz: bccd692489a429f25b11146b05af9bf83069bc7030190784e4d6689f7952e08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736797b5859756d0de5538d45760b146acad553c39a25c2d868b04cf1ad6710cf5c9925ac7eb9e50bd825466c30bff6114b6295009407d9772806bd1ddc0930b
|
7
|
+
data.tar.gz: 424c018cb3b2eeca345ba621049ce90d412565849b4f769193587ae94dc9eb0b8f14806cf22fba666e05f1f3f6b1fcb8a78736a1c872e8adcf3ca7e7816b4d35
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
asynr (1.0
|
5
|
-
rufus-scheduler (~> 3.6.0)
|
4
|
+
asynr (1.3.0)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
|
-
concurrent-ruby (1.1.5)
|
11
9
|
diff-lcs (1.3)
|
12
|
-
et-orbi (1.2.2)
|
13
|
-
tzinfo
|
14
|
-
fugit (1.3.3)
|
15
|
-
et-orbi (~> 1.1, >= 1.1.8)
|
16
|
-
raabro (~> 1.1)
|
17
|
-
raabro (1.1.6)
|
18
10
|
rake (10.5.0)
|
19
11
|
rspec (3.8.0)
|
20
12
|
rspec-core (~> 3.8.0)
|
@@ -29,10 +21,6 @@ GEM
|
|
29
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
22
|
rspec-support (~> 3.8.0)
|
31
23
|
rspec-support (3.8.2)
|
32
|
-
rufus-scheduler (3.6.0)
|
33
|
-
fugit (~> 1.1, >= 1.1.6)
|
34
|
-
tzinfo (2.0.0)
|
35
|
-
concurrent-ruby (~> 1.0)
|
36
24
|
|
37
25
|
PLATFORMS
|
38
26
|
ruby
|
@@ -42,7 +30,6 @@ DEPENDENCIES
|
|
42
30
|
bundler (~> 2.0)
|
43
31
|
rake (~> 10.0)
|
44
32
|
rspec (~> 3.0)
|
45
|
-
rufus-scheduler
|
46
33
|
|
47
34
|
BUNDLED WITH
|
48
35
|
2.0.2
|
data/README.md
CHANGED
@@ -1,115 +1,108 @@
|
|
1
1
|
# Asynr
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
```bash
|
8
|
-
$ gem install asynr
|
9
|
-
$ echo "gem 'asynr'" >> Gemfile
|
10
|
-
$ bundle install
|
11
|
-
```
|
12
|
-
|
13
|
-
# How to use
|
14
|
-
|
15
|
-
## Minimal setup
|
3
|
+
(This gem is a rebuild of a previous one located at the same Github repository).
|
4
|
+
\
|
5
|
+
Asynr is a gem to perform asynchronous tasks by evaluating directly classes and entrypoints.
|
6
|
+
This is highly inspired by Rufus-Scheduler.
|
16
7
|
|
17
|
-
|
8
|
+
## How it works ?
|
18
9
|
|
10
|
+
When you want to create a scheduler running several tasks separated by classes, you can instantiate Asynr and launch them asynchronously an easy way.
|
11
|
+
\
|
12
|
+
Asynr is based-upon Ruby threads and requires no dependency.
|
19
13
|
```ruby
|
14
|
+
# example
|
20
15
|
require "asynr"
|
21
|
-
|
22
|
-
|
16
|
+
Dir.glob(Dir.pwd + "/lib/*_class.rb").each &method(:require)
|
17
|
+
|
18
|
+
class Worker
|
19
|
+
def self._start
|
20
|
+
scheduler = Asynr.new
|
21
|
+
scheduler.in 3, ARandomClass
|
22
|
+
scheduler.every 3600, 2, AnotherClass, {entrypoint: :new}
|
23
|
+
scheduler.at (Time.now + 10), AgainAnother, {arg1: :hello, arg2: :world}
|
24
|
+
|
25
|
+
scheduler.start
|
26
|
+
end
|
27
|
+
end
|
23
28
|
```
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
* name: each job has a name which can be used to remove the concerned job.
|
30
|
-
* action: is the evaluated class name. Async will search for a run method inside of this class.
|
31
|
-
* first_in: directly taken from Rufus, time before the action starts.
|
32
|
-
* every: time between two class executions.
|
30
|
+
* We require asynr and all the files containing independant classes.
|
31
|
+
* We instantiate a new scheduler, which is gonna be empty
|
32
|
+
* We create .in, .every and .at jobs (read definitions)
|
33
|
+
* We start it
|
33
34
|
|
34
|
-
##
|
35
|
+
## launch a job in two days
|
35
36
|
|
36
|
-
|
37
|
+
```ruby
|
38
|
+
secrets = File.read '/a/secret/path/secrets.txt'
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
inst.queue.length # 1
|
42
|
-
inst.remove :Test
|
43
|
-
inst.queue.length # 0
|
44
|
-
...
|
40
|
+
scheduler = Asynr.new
|
41
|
+
scheduler.at (Time.now + (3600 * 24) * 2), BackupFiles, {password: secrets}
|
42
|
+
scheduler.start
|
45
43
|
```
|
46
44
|
|
47
|
-
|
45
|
+
In this example, we are using the arguments API of Asynr. It allows us to bind any value to any key when calling a .in, .every or .at method.
|
48
46
|
|
49
|
-
Once launched, a new job cannot be defined and added. We need to set all the jobs and related timers before starting the scheduler.
|
50
47
|
|
48
|
+
## launch a job every hour
|
51
49
|
```ruby
|
52
|
-
|
50
|
+
url = "https://acoolwebsitetoscrap.com"
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
inst.queue.length # 2
|
58
|
-
|
59
|
-
inst.start!
|
52
|
+
scheduler = Asynr.new
|
53
|
+
scheduler.every 3600, 0, WebScrapper, {entrypoint: :new, url: url, save_to: "/tmp/scrapper"}
|
54
|
+
scheduler.start
|
60
55
|
```
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
Since the logic behind it may confuse you regarding the class evaluation, here's a working example of how to use Asynr. Minimal yet functionnal.
|
57
|
+
We typically want to download a whole page every hour since it may change soon. This snippet allows you to send the url and the path where you want to save scrapped file.
|
65
58
|
\
|
66
|
-
This example will save a HTTP request launched every 60 seconds, for ever (until it is stopped).
|
67
59
|
|
60
|
+
### Entrypoint argument
|
61
|
+
Entrypoint is a quite special argument, since it allows you to select which class method is gonna be called by the class evaluator. `new` allows you to create objects, and the default value is `self._entrypoint`.
|
62
|
+
|
63
|
+
Here is what a default Asynr-compliante class may look like.
|
68
64
|
```ruby
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
f.puts res.body
|
77
|
-
end
|
65
|
+
class WebScrapper
|
66
|
+
def self._entrypoint(*args)
|
67
|
+
body = AnyHTTPLib.get(URI.parse(args[:url])).body
|
68
|
+
f = File.open("%s/%s" % [args[:save_to], Time.now.strftime('%y-%m-%d')])
|
69
|
+
f.puts body
|
70
|
+
f.close
|
71
|
+
end
|
78
72
|
end
|
73
|
+
```
|
79
74
|
|
80
|
-
|
81
|
-
|
82
|
-
|
75
|
+
## Launch a job in two minutes
|
76
|
+
```ruby
|
77
|
+
scheduler = Asynr.new
|
78
|
+
scheduler.in 120, PrintHelloWorld
|
83
79
|
```
|
84
80
|
|
85
|
-
|
81
|
+
This is a quite easy method to understand. Please mind you are free to put arguments at the end of this line or select another entrypoint than `_entrypoint`.
|
86
82
|
|
87
|
-
|
83
|
+
# Why an entrypoint ?
|
84
|
+
Ruby doesn't have any entrypoint function as main() could be one in Go, for example. This function is typically intended to provide a "entrypoint" where function-calls tree will be created and attached to. Since Ruby doesn't have it, without a entrypoint method, Asynr wouldn't be able to load and execute the class in a cool way.
|
88
85
|
\
|
89
|
-
|
86
|
+
I called this temporary main method `_entrypoint`. The `_` means it is special and it allows us to avoid common names mistakes. This method must be registred as `self` into a class to be called as it.
|
90
87
|
|
91
|
-
```
|
92
|
-
|
93
|
-
scheduler.rb
|
94
|
-
worker/
|
95
|
-
- download_first_file.rb
|
96
|
-
- download_second_file.rb
|
97
|
-
- download_third_file.rb
|
98
|
-
lib/
|
99
|
-
- dependency.rb
|
88
|
+
```ruby
|
89
|
+
class RandomTest ; def self._entrypoint(*args) ; end ; end
|
100
90
|
```
|
101
91
|
|
102
|
-
|
92
|
+
You can override this parameter (in order to create instance through .new method, for example) by adding a `{entrypoint: :any_method}` argument to .in, .every and .at methods.
|
93
|
+
\
|
94
|
+
Please note the `*args` method parameter. It allows us to bind any information comming from the scheduler to attach it into the entrypoint method.
|
103
95
|
\
|
104
|
-
|
96
|
+
Working example :
|
105
97
|
```ruby
|
106
|
-
|
107
|
-
Dir.glob(Dir.pwd + "/worker/*.rb").each &method(:require)
|
98
|
+
url = "https://rubygems.org"
|
108
99
|
|
109
|
-
|
110
|
-
|
111
|
-
asynr.job(name: :secondFile, action: DownloadSecondFile, first_in: 0, every: 60)
|
112
|
-
asynr.job(name: :thirFile, action: DownloadThirdFile, first_in: 0, every: 60)
|
100
|
+
scheduler = Asynr.new
|
101
|
+
scheduler.in 3, DisplaySomething, {text: url}
|
113
102
|
|
114
|
-
|
103
|
+
class DisplaySomething
|
104
|
+
def self._entrypoint(*args)
|
105
|
+
puts args[:text]
|
106
|
+
end
|
107
|
+
end
|
115
108
|
```
|
data/asynr.gemspec
CHANGED
@@ -5,19 +5,19 @@ require "asynr/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "asynr"
|
7
7
|
spec.version = Asynr::VERSION
|
8
|
-
spec.authors = ["
|
9
|
-
spec.email = ["
|
8
|
+
spec.authors = ["Gautier François"]
|
9
|
+
spec.email = ["gfrancois@online.net"]
|
10
10
|
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
13
|
-
spec.homepage = "https://
|
11
|
+
spec.summary = %q{Asynchronous scheduler based upon threads.}
|
12
|
+
spec.description = %q{Asynr evaluates asynchrounsly Ruby classes by calling entrypoint methods. It intends to be useful to schedule job tasks an easier way than currently.}
|
13
|
+
spec.homepage = "https://github.com/atilleh/asynr"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/atilleh/
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/atilleh/
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/atilleh/asynr"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/atilleh/asynr/tree/master/CHANGELOG.md"
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -31,7 +31,4 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
-
spec.add_development_dependency "rufus-scheduler"
|
35
|
-
|
36
|
-
spec.add_runtime_dependency 'rufus-scheduler', '~> 3.6.0'
|
37
34
|
end
|
data/lib/asynr.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
require "asynr/version"
|
2
2
|
require "asynr/core"
|
3
3
|
require "asynr/job"
|
4
|
+
require "asynr/scheduler"
|
4
5
|
|
5
6
|
module Asynr
|
6
7
|
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @param params [Hash] defaults options
|
12
|
-
# @return self [Object] self from Asynr::Core
|
8
|
+
# Create a new scheduler
|
9
|
+
# @param params [Hash] default option to create a scheduler.
|
10
|
+
# @return self [Object] scheduler object from #Core
|
13
11
|
def self.new(params={})
|
14
|
-
|
12
|
+
Core.new(params)
|
15
13
|
end
|
16
14
|
|
17
15
|
class Error < StandardError; end
|
data/lib/asynr/core.rb
CHANGED
@@ -1,52 +1,68 @@
|
|
1
|
-
require "rufus-scheduler"
|
2
|
-
|
3
1
|
module Asynr
|
4
|
-
#
|
2
|
+
# Core class exposes user-related methods
|
3
|
+
# to configure the scheduler jobs.
|
5
4
|
class Core
|
6
|
-
|
7
|
-
# populate the local queue.
|
8
|
-
# This local queue is gonna be converted into a
|
9
|
-
# rufus queue.
|
10
|
-
def initialize(params={})
|
5
|
+
def initialize(params)
|
11
6
|
@params = params
|
12
|
-
@
|
13
|
-
|
7
|
+
@scheduler = {
|
8
|
+
jobs: []
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create a new :in job
|
13
|
+
# @param seconds [Int32] seconds to wait before running the job
|
14
|
+
# @param action_class [Object] class to evaluate
|
15
|
+
# @param arguments [Hash] optional arguments to pass to the job creator.
|
16
|
+
def in(seconds, action_class, *arguments)
|
17
|
+
@scheduler[:jobs].append(Job.new(
|
18
|
+
type: :in,
|
19
|
+
params: { seconds: seconds },
|
20
|
+
action: action_class,
|
21
|
+
arguments: arguments ||= nil
|
22
|
+
))
|
14
23
|
end
|
15
24
|
|
16
|
-
#
|
17
|
-
|
18
|
-
|
25
|
+
# Create a new :every job
|
26
|
+
# @param seconds [Int32] seconds to wait between two occurences
|
27
|
+
# @param delay [Int32] amount of seconds before running it the first time
|
28
|
+
# @param action_class [Object] class to instantiate and execute.
|
29
|
+
# @param arguments [Hash] optional argument to transmit to the entrypoint.
|
30
|
+
def every(seconds, delay, action_class, *arguments)
|
31
|
+
@scheduler[:jobs].append(Job.new(
|
32
|
+
type: :every,
|
33
|
+
params: { seconds: seconds, delay: delay},
|
34
|
+
action: action_class,
|
35
|
+
arguments: arguments ||= nil
|
36
|
+
))
|
19
37
|
end
|
20
38
|
|
21
|
-
# Create a new job
|
22
|
-
# @
|
23
|
-
# @
|
24
|
-
|
25
|
-
|
26
|
-
@
|
27
|
-
|
39
|
+
# Create a new :at job
|
40
|
+
# @param date_to [Object] Time object cursor to run the job.
|
41
|
+
# @param action_class [Object] class to instantiate and execute.
|
42
|
+
# @param arguments [hash] optional arguments to transmit to the entrypoint.
|
43
|
+
def at(date_to, action_class, *arguments)
|
44
|
+
@scheduler[:jobs].append(Job.new(
|
45
|
+
type: :at,
|
46
|
+
params: { date: date_to },
|
47
|
+
action: action_class,
|
48
|
+
arguments: arguments ||= nil
|
49
|
+
))
|
28
50
|
end
|
29
51
|
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
def remove(name)
|
34
|
-
@local_queue.delete_if {|i| i.name == name}
|
52
|
+
# Starts the scheduler.
|
53
|
+
def start
|
54
|
+
Scheduler.new(@scheduler)
|
35
55
|
end
|
36
56
|
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
dispatch!
|
41
|
-
@queue.join
|
57
|
+
# @return @scheduler [Hash] current scheduler instance
|
58
|
+
def config
|
59
|
+
@scheduler
|
42
60
|
end
|
43
61
|
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@queue.every job.every, first_in: job.first_in do job.action.send(:run) ; end
|
49
|
-
end
|
50
|
-
end
|
62
|
+
# @return @scheduler [Hash] current job queue
|
63
|
+
def jobs
|
64
|
+
@scheduler[:jobs]
|
65
|
+
end
|
51
66
|
end
|
52
|
-
end
|
67
|
+
end
|
68
|
+
|
data/lib/asynr/job.rb
CHANGED
@@ -1,31 +1,59 @@
|
|
1
1
|
module Asynr
|
2
|
-
|
3
|
-
# Class for job initialization
|
4
2
|
class Job
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def
|
3
|
+
def initialize(job_descriptor)
|
4
|
+
@job = job_descriptor
|
5
|
+
@job[:metas] = {
|
6
|
+
created_at: Time.now,
|
7
|
+
created_at_timestamp: Time.now.to_i,
|
8
|
+
updated_at: Time.now,
|
9
|
+
status: :awaiting
|
10
|
+
}
|
11
|
+
|
12
|
+
if job_descriptor[:arguments][0].key? :entrypoint
|
13
|
+
@job[:entrypoint] = job_descriptor[:arguments][0][:entrypoint]
|
14
|
+
else
|
15
|
+
@job[:entrypoint] = :_entrypoint
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def type
|
20
|
+
@job[:type]
|
21
|
+
end
|
22
|
+
|
23
|
+
def params
|
24
|
+
@job[:params]
|
25
|
+
end
|
26
|
+
|
27
|
+
def arguments
|
28
|
+
@job[:arguments]
|
29
|
+
end
|
30
|
+
|
31
|
+
def action
|
32
|
+
@job[:action]
|
33
|
+
end
|
34
|
+
|
35
|
+
def metas
|
36
|
+
@job[:metas]
|
37
|
+
end
|
38
|
+
|
39
|
+
def update
|
40
|
+
@job[:metas][:updated_at] = Time.now
|
41
|
+
end
|
42
|
+
|
43
|
+
def declare_running
|
44
|
+
@job[:metas][:status] = :running
|
45
|
+
end
|
46
|
+
|
47
|
+
def declare_finished
|
48
|
+
@job[:metas][:status] = :finished
|
49
|
+
end
|
50
|
+
|
51
|
+
def declare_scheduled
|
52
|
+
@job[:metas][:status] = :scheduled
|
53
|
+
end
|
54
|
+
|
55
|
+
def entrypoint
|
56
|
+
@job[:entrypoint]
|
57
|
+
end
|
30
58
|
end
|
31
59
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Asynr
|
2
|
+
# Scheduler class creates new threads for any job
|
3
|
+
# added to scheduler.
|
4
|
+
# @see Core#start
|
5
|
+
class Scheduler
|
6
|
+
# Creates an empty array of threads
|
7
|
+
# For each job, determines its type and create a thread based
|
8
|
+
# on it.
|
9
|
+
# Finally, executes the threads.
|
10
|
+
def initialize(scheduler)
|
11
|
+
@threads = []
|
12
|
+
scheduler[:jobs].each do |job|
|
13
|
+
@threads.append(_in(job)) if job.type == :in
|
14
|
+
@threads.append(_every(job)) if job.type == :every
|
15
|
+
@threads.append(_at(job)) if job.type == :at
|
16
|
+
end
|
17
|
+
|
18
|
+
@threads.each do |thr|
|
19
|
+
p thr.inspect
|
20
|
+
thr.join
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
# Creates a new :in job.
|
26
|
+
# @param job [Object] job instance
|
27
|
+
# @return thx [Thread] thread transition
|
28
|
+
def _in(job)
|
29
|
+
thx = Thread.new do
|
30
|
+
job.declare_running
|
31
|
+
sleep job.params[:seconds]
|
32
|
+
job.action.send(job.entrypoint, job.arguments[0])
|
33
|
+
job.update
|
34
|
+
job.declare_finished
|
35
|
+
end
|
36
|
+
|
37
|
+
thx
|
38
|
+
end
|
39
|
+
|
40
|
+
# Creates a new :every job
|
41
|
+
# Will sleep if a delay has been set.
|
42
|
+
# Will be executed only once if kill parameter submitted.
|
43
|
+
# @param job [Object] job instance
|
44
|
+
# @return thx [Thread] thread transition
|
45
|
+
def _every(job)
|
46
|
+
thx = Thread.new do |thx|
|
47
|
+
job.declare_running
|
48
|
+
sleep job.params[:delay] ||= 0
|
49
|
+
x = true
|
50
|
+
|
51
|
+
while x == true
|
52
|
+
job.action.send(job.entrypoint, job.arguments[0])
|
53
|
+
job.update
|
54
|
+
|
55
|
+
if job.arguments[0][:kill]
|
56
|
+
puts "Job will sleep."
|
57
|
+
x = false
|
58
|
+
end
|
59
|
+
|
60
|
+
sleep job.params[:seconds]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
thx
|
65
|
+
end
|
66
|
+
|
67
|
+
# Creates a new :at job
|
68
|
+
# Will be killed if kill argument specified.
|
69
|
+
# By default, execute the same job every day.
|
70
|
+
# @param job [Object] job object
|
71
|
+
# @return thx [Thread] thread transition
|
72
|
+
def _at(job)
|
73
|
+
thx = Thread.new do |thx|
|
74
|
+
job.declare_scheduled
|
75
|
+
|
76
|
+
x = false
|
77
|
+
|
78
|
+
while x == false
|
79
|
+
if Time.now.to_i == job.params[:date].to_i
|
80
|
+
job.declare_running
|
81
|
+
job.action.send(job.entrypoint, job.arguments[0])
|
82
|
+
job.update
|
83
|
+
job.declare_finished
|
84
|
+
|
85
|
+
if job.arguments[0][:kill]
|
86
|
+
x = true
|
87
|
+
end
|
88
|
+
|
89
|
+
job.params[:date] = Time.now + 86400
|
90
|
+
else
|
91
|
+
sleep 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
thx
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
data/lib/asynr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asynr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Gautier François
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,38 +52,10 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
|
56
|
-
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rufus-scheduler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 3.6.0
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 3.6.0
|
83
|
-
description: Async job planner based upon Rufus scheduler Ruby gem and threads, with
|
84
|
-
history and states.
|
55
|
+
description: Asynr evaluates asynchrounsly Ruby classes by calling entrypoint methods.
|
56
|
+
It intends to be useful to schedule job tasks an easier way than currently.
|
85
57
|
email:
|
86
|
-
-
|
58
|
+
- gfrancois@online.net
|
87
59
|
executables: []
|
88
60
|
extensions: []
|
89
61
|
extra_rdoc_files: []
|
@@ -103,15 +75,16 @@ files:
|
|
103
75
|
- lib/asynr.rb
|
104
76
|
- lib/asynr/core.rb
|
105
77
|
- lib/asynr/job.rb
|
78
|
+
- lib/asynr/scheduler.rb
|
106
79
|
- lib/asynr/version.rb
|
107
|
-
homepage: https://
|
80
|
+
homepage: https://github.com/atilleh/asynr
|
108
81
|
licenses:
|
109
82
|
- MIT
|
110
83
|
metadata:
|
111
84
|
allowed_push_host: https://rubygems.org
|
112
|
-
homepage_uri: https://
|
113
|
-
source_code_uri: https://github.com/atilleh/
|
114
|
-
changelog_uri: https://github.com/atilleh/
|
85
|
+
homepage_uri: https://github.com/atilleh/asynr
|
86
|
+
source_code_uri: https://github.com/atilleh/asynr
|
87
|
+
changelog_uri: https://github.com/atilleh/asynr/tree/master/CHANGELOG.md
|
115
88
|
post_install_message:
|
116
89
|
rdoc_options: []
|
117
90
|
require_paths:
|
@@ -131,5 +104,5 @@ rubyforge_project:
|
|
131
104
|
rubygems_version: 2.7.6.2
|
132
105
|
signing_key:
|
133
106
|
specification_version: 4
|
134
|
-
summary:
|
107
|
+
summary: Asynchronous scheduler based upon threads.
|
135
108
|
test_files: []
|