hardcode 0.0.1 → 0.1.0

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: 5127cde3129d52731e40cd2079ffbd8d5fe01ecb
4
- data.tar.gz: 3fedee971f787fc479abf0af1dfbb3e9c18018a8
3
+ metadata.gz: 40c0f39fc533c3f27a074f8a323959dda66b91f1
4
+ data.tar.gz: f26b0c0e1a7f1e7fdc859c148b8f85525a1c1ad7
5
5
  SHA512:
6
- metadata.gz: 33b928212ee43de7f5a8b39976287e75755096e6216e61b74d7eac98117d7af2c15efc755c1cf3d613411d865dda490444ff433762d09782a285a910c995d386
7
- data.tar.gz: 96284c72af24de8eacdc2f3bdb6ada085ac58d408abb24b9b863b57cb9f88d0c8dd0626ea5620fea64e480a50cfec62de6c1b710074efdeed16d882f35694698
6
+ metadata.gz: 84453481f1704267de1aca0a02a3be89536518ecd2e1add79f02de5d1ade64442f1b04de2a4aafa67272e2c2add28ec9deb72e39b5c1ac59fd3f71b74e262381
7
+ data.tar.gz: b71b8eea7ec1517f8ce4c8d46856b359b92294058e8691c4d474cb7cc23d1ac3b3c981e42f46eac86597a769692534bea5c348e34da56e20cb9c0b3f20ffd29f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Hardcode
2
2
 
3
- (stack-encode)[https://github.com/swisstxt/stack-encode] on steroids (using a rabbitmq worker queue)
3
+ [stack-encode](https://github.com/swisstxt/stack-encode) on steroids (using a rabbitmq worker queue)
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,9 +20,23 @@ run `harcode help` for instructions
20
20
 
21
21
  ### Example: Enqueue Encoding Jobs to RabbitMQ
22
22
 
23
+ Scan a directory for multimedia file, move them to the tmp directory and enqueue transcoding jobs if needed:
24
+
25
+ ```bash
26
+ hardcode enqueue /home/media/import --destination /var/www/videos
27
+ ```
28
+
29
+ ### Example: Start the workers
30
+
31
+ Starts the sneakers based workers which will wait for transcoding jobs coming from the RabbitMQ queue:
32
+
33
+ ```bash
34
+ hardcode work --debug
35
+ ```
36
+
23
37
  ## Running the worker in production
24
38
 
25
- Put the following systemd configuration under /usr/lib/systemd/system/hardcode.service (for RHEL/CentOS 7) and adapt it to your needs:
39
+ Put the following systemd configuration under /usr/lib/systemd/system/hardcode-worker.service (for RHEL/CentOS 7) and adapt it to your needs:
26
40
 
27
41
  ```
28
42
  [Unit]
@@ -34,7 +48,7 @@ After=network.target
34
48
  Type=simple
35
49
  User=root
36
50
  Group=root
37
- ExecStart=hardcode work
51
+ ExecStart=/usr/local/bin/hardcode work
38
52
 
39
53
  # Give a reasonable amount of time for the workers to start up/shut down
40
54
  TimeoutSec=300
@@ -43,6 +57,13 @@ TimeoutSec=300
43
57
  WantedBy=multi-user.target
44
58
  ```
45
59
 
60
+ Start the workers using systemd and enable it at boottime:
61
+
62
+ ```bash
63
+ systemctl start hardcode-worker.service
64
+ systemctl enable hardcode-worker.service
65
+ ```
66
+
46
67
  ## Contributing
47
68
 
48
69
  1. Fork it ( https://github.com/[my-github-username]/hardcode/fork )
data/Rakefile CHANGED
@@ -1,3 +1,2 @@
1
- require "bundler/gem_tasks"
2
1
  require 'bundler'
3
2
  Bundler::GemHelper.install_tasks
data/hardcode.gemspec CHANGED
@@ -22,8 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "sneakers"
23
23
  spec.add_dependency "bunny", ">= 0.9.1"
24
24
  spec.add_dependency "json"
25
+ spec.add_dependency "listen"
25
26
  spec.add_dependency "stack-encode"
26
27
 
27
- spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "bundler"
28
29
  spec.add_development_dependency "rake"
29
30
  end
data/lib/hardcode/cli.rb CHANGED
@@ -93,5 +93,43 @@ module Hardcode
93
93
  r.run
94
94
  end
95
95
 
96
+ desc "watch DIR", "Watch a source directory for new files, moves the files to tmp and enqueues transcoding jobs to rabbitmq"
97
+ option :destination,
98
+ desc: "destination directory",
99
+ aliases: '-d',
100
+ default: '/var/www/'
101
+ option :tmp_dir,
102
+ desc: "temporary directory",
103
+ aliases: '-t',
104
+ default: '/tmp'
105
+ def watch(source_dir)
106
+ FileUtils.touch LOCK_FILE
107
+ conn = Bunny.new
108
+ conn.start
109
+ ch = conn.create_channel
110
+ q = ch.queue('stack_encode', durable: true)
111
+ listener = Listen.to(source_dir) do |modified, added, removed|
112
+ unless added.empty?
113
+ source_file = added.first
114
+ # wait until the file is fully written and not uploaded anymore
115
+ while system %Q[lsof '#{source_file}']
116
+ sleep 1
117
+ end
118
+ FileUtils.mv(source_file, options[:tmp_dir], verbose: true)
119
+ ch.default_exchange.publish(
120
+ {
121
+ source: File.join(options[:tmp_dir], File.basename(source_file)),
122
+ dest_dir: options[:destination]
123
+ }.to_json,
124
+ routing_key: q.name,
125
+ persistent: true
126
+ )
127
+ end
128
+ end
129
+ listener.start
130
+ sleep
131
+ end
132
+ end
133
+
96
134
  end # class
97
135
  end # module
@@ -1,3 +1,3 @@
1
1
  module Hardcode
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hardcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - niwo
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: listen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: stack-encode
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +98,16 @@ dependencies:
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - "~>"
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: '1.6'
103
+ version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - "~>"
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: '1.6'
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement