hardcode 0.0.1 → 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 +4 -4
- data/README.md +24 -3
- data/Rakefile +0 -1
- data/hardcode.gemspec +2 -1
- data/lib/hardcode/cli.rb +38 -0
- data/lib/hardcode/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40c0f39fc533c3f27a074f8a323959dda66b91f1
|
4
|
+
data.tar.gz: f26b0c0e1a7f1e7fdc859c148b8f85525a1c1ad7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84453481f1704267de1aca0a02a3be89536518ecd2e1add79f02de5d1ade64442f1b04de2a4aafa67272e2c2add28ec9deb72e39b5c1ac59fd3f71b74e262381
|
7
|
+
data.tar.gz: b71b8eea7ec1517f8ce4c8d46856b359b92294058e8691c4d474cb7cc23d1ac3b3c981e42f46eac86597a769692534bea5c348e34da56e20cb9c0b3f20ffd29f
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Hardcode
|
2
2
|
|
3
|
-
|
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
|
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
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"
|
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
|
data/lib/hardcode/version.rb
CHANGED
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
|
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: '
|
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: '
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rake
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|