philbot-scheduler 1.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/scheduler.rb +43 -0
  3. metadata +42 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e1b09cd01754218e2b11d3f153d5e407c010fb11827c330128f71549b64d40b2
4
+ data.tar.gz: bb003f15c4044225c78bcb362acd2709b47fec121eedcdd62f6898912b09d9dc
5
+ SHA512:
6
+ metadata.gz: e45b7a6d47877e07e96736a1bc6a561426b8a6490fc174a755bd3a10cebcf914df43d45ae40b69a3af88ff3826fe12a1c288a3d98c0ee2d657d76d48f8953cc1
7
+ data.tar.gz: 68631fbfcfef4a644631535bb94410f141e8fcd14aca714b04a555f03328ce5f6a0776da8db65831a7cb16fcfef9d59fa4f953e8750ffe8089315d08c68072d6
data/scheduler.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ def get_sleep_time(interval)
5
+ time = Time.new
6
+ sleep_time = 60 - time.sec
7
+ if interval == 'minutely' then return sleep_time end
8
+ sleep_time += (60 - time.min) * 60
9
+ if interval == 'hourly' then return sleep_time end
10
+ sleep_time += (24 - time.hour) * 60 * 60
11
+ if interval == 'daily' then return sleep_time end
12
+ sleep_time += (31 - time.day) * 24 * 60 * 60
13
+ if interval == 'monthly' then return sleep_time end
14
+ exit(1)
15
+ end
16
+
17
+ puts "running"
18
+ threads = []
19
+ File.open(ENV["CONFIG_FILE"]).readlines.map(&:chomp).each do |line|
20
+ puts 'config ' + line
21
+ tokens = line.split(/=/)
22
+ if tokens.length != 2 then
23
+ puts 'broken config'
24
+ exit(1)
25
+ end
26
+ interval = tokens[0]
27
+ url = tokens[1]
28
+
29
+ threads << Thread.new {
30
+ while true
31
+ sleep(get_sleep_time(interval))
32
+ puts url
33
+ begin
34
+ Net::HTTP.post(URI(url), '{}', { 'content-encoding' => 'identity', 'content-type' => 'application/json' })
35
+ rescue
36
+ end
37
+ end
38
+ }
39
+ end
40
+
41
+ threads.each do |thread|
42
+ thread.join();
43
+ end
metadata ADDED
@@ -0,0 +1,42 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: philbot-scheduler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Philipp Lengauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-12-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: p.lengauer@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - scheduler.rb
20
+ homepage:
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubygems_version: 3.3.5
39
+ signing_key:
40
+ specification_version: 4
41
+ summary: ''
42
+ test_files: []