sidetiq-timezone 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad2cffa7fe055e2e0e43be5633b4fa19db3ed8a2
4
+ data.tar.gz: 2835f57e2fe7ae718bf3d475045274efc21085b1
5
+ SHA512:
6
+ metadata.gz: 8b4d3a7f504f1d2850e78fff60c147d57adcdacbb89093f1af27493a66b7c3b11a0c7dc3e2485b77e88d7fe38012d3914c71d858b8a4c0f9c9ed789bd06ab8d0
7
+ data.tar.gz: f552141ec9f6ed598179e4eb4782690ecf7dd7a43f49d6669fd546b442462602a798c901d16abce10e0d77c6d8871ead0921a949566fb71ed492b5217b122e92
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sidetiq-timezone.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2014-2015 Akinori MUSHA
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions
7
+ are met:
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Sidetiq::Timezone
2
+
3
+ This library adds time zone support to Sidetiq. You can name a time
4
+ zone for Sidetiq to use or just let it honor the value of `Time.zone`.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'sidetiq-timezone'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install sidetiq-timezone
21
+
22
+ ## Usage
23
+
24
+ If you want to explicitly specify a time zone for the Sidetiq
25
+ scheduler, call `Sidetiq.clock.time_zone=` as follows somewhere in
26
+ your application like `config/initializers/sidetiq.rb` if you are
27
+ using Rails.
28
+
29
+ ```ruby
30
+ Sidetiq.clock.time_zone = ActiveSupport::TimeZone['Tokyo']
31
+ ```
32
+
33
+ Otherwise, it is automatically set to `Time.zone` when the first class
34
+ to include `Sidetiq::Schedulable` is defined.
35
+
36
+ There is no per-worker time zone support since Sidetiq currently has
37
+ just one shared clock that rules all scheduled workers.
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/knu/sidetiq-timezone/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
52
+
53
+ ## Author
54
+
55
+ Copyright (c) 2014-2015 Akinori MUSHA.
56
+
57
+ Licensed under the 2-clause BSD license. See `LICENSE.txt` for
58
+ details.
59
+
60
+ Visit the [GitHub Repository](https://github.com/knu/sidetiq-timezone)
61
+ for the latest information.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sidetiq/timezone"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ # :markup: markdown
2
+
3
+ require 'sidetiq'
4
+ require 'active_support/time'
5
+
6
+ module Sidetiq
7
+ # Adds time zone support to Sidetiq.
8
+ module Timezone
9
+ end
10
+ end
11
+
12
+ require 'sidetiq/timezone/version'
13
+ require 'sidetiq/timezone/clock'
14
+ require 'sidetiq/timezone/schedule'
15
+ require 'sidetiq/timezone/schedulable'
@@ -0,0 +1,38 @@
1
+ # :markup: markdown
2
+
3
+ module Sidetiq
4
+ module Timezone
5
+ # Adds an accessor `time_zone`.
6
+ module Clock
7
+ attr_accessor :time_zone
8
+
9
+ def time_zone=(time_zone)
10
+ info "Using the time zone: #{time_zone ? time_zone.name : 'none'}"
11
+ @time_zone = time_zone
12
+ end
13
+
14
+ def gettime
15
+ if @time_zone
16
+ @time_zone.now
17
+ else
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ class Clock
25
+ prepend Timezone::Clock
26
+
27
+ ##
28
+ # :attr_accessor: time_zone
29
+ #
30
+ # Time zone for Sidetiq. If you don't set this, it is
31
+ # automatically set to `Time.zone` when the first class to include
32
+ # `Sidetiq::Schedulable` is defined.
33
+ #
34
+ # ```ruby
35
+ # Sidetiq.clock.time_zone = ActiveSupport::TimeZone['Tokyo']
36
+ # ```
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ # :markup: markdown
2
+
3
+ module Sidetiq
4
+ module Timezone
5
+ module Schedulable
6
+ # Automatically sets the application time zone for Sidetiq when
7
+ # a (first) worker is defined.
8
+ module ClassMethods
9
+ def included(klass)
10
+ super
11
+ Sidetiq.clock.time_zone ||= Time.zone
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ module Schedulable
18
+ class << self
19
+ prepend Timezone::Schedulable::ClassMethods
20
+ end
21
+
22
+ module ClassMethods
23
+ # Returns Sidetiq.clock.time_zone.
24
+ def time_zone
25
+ Sidetiq.clock.time_zone
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # :markup: markdown
2
+
3
+ module Sidetiq
4
+ module Timezone
5
+ module Schedule
6
+ # Makes start_time adopt the application time zone.
7
+ module ClassMethods
8
+ def start_time
9
+ start_time = super
10
+ if time_zone = Sidetiq.clock.time_zone
11
+ time_zone.local(start_time.year, start_time.month, start_time.day)
12
+ else
13
+ start_time
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class Schedule
21
+ class << self
22
+ prepend Timezone::Schedule::ClassMethods
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # :markup: markdown
2
+
3
+ module Sidetiq
4
+ module Timezone
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sidetiq/timezone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sidetiq-timezone"
8
+ spec.version = Sidetiq::Timezone::VERSION
9
+ spec.authors = ["Akinori MUSHA"]
10
+ spec.email = ["knu@idaemons.org"]
11
+
12
+ # if spec.respond_to?(:metadata)
13
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
14
+ # end
15
+
16
+ spec.summary = %q{Time zone support for Sidetiq}
17
+ spec.description = <<'EOF'
18
+ This library adds time zone support to Sidetiq.
19
+
20
+ You can name a time zone for Sidetiq to use or just let it honor the
21
+ value of `Time.zone`.
22
+ EOF
23
+ spec.homepage = "https://github.com/knu/sidetiq-timezone"
24
+ spec.license = "2-clause BSDL"
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_runtime_dependency "sidetiq", "~> 0.6.0"
32
+ spec.add_runtime_dependency "activesupport", ">= 0"
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.8"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidetiq-timezone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Akinori MUSHA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidetiq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: |
70
+ This library adds time zone support to Sidetiq.
71
+
72
+ You can name a time zone for Sidetiq to use or just let it honor the
73
+ value of `Time.zone`.
74
+ email:
75
+ - knu@idaemons.org
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".rspec"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/sidetiq/timezone.rb
89
+ - lib/sidetiq/timezone/clock.rb
90
+ - lib/sidetiq/timezone/schedulable.rb
91
+ - lib/sidetiq/timezone/schedule.rb
92
+ - lib/sidetiq/timezone/version.rb
93
+ - sidetiq-timezone.gemspec
94
+ homepage: https://github.com/knu/sidetiq-timezone
95
+ licenses:
96
+ - 2-clause BSDL
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Time zone support for Sidetiq
118
+ test_files: []
119
+ has_rdoc: