Skip to content

Commit fd22667

Browse files
committed
Add contrib driver for Hashicorp Nomad jobs
Based on the Kubernetes contrib, but different.
1 parent cf4b6fb commit fd22667

File tree

3 files changed

+531
-0
lines changed

3 files changed

+531
-0
lines changed

examples/nomad.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2021 Volvo Car Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
"""
18+
Example Nomad Job Task.
19+
20+
Requires:
21+
22+
- nomad: ``pip install python-nomad``
23+
- A local nomad cluster up and running: https://learn.hashicorp.com/nomad
24+
25+
You can run this code example like this:
26+
27+
.. code:: console
28+
$ luigi --module examples.nomad PerlPi --local-scheduler
29+
30+
Running this code will create a pi-luigi-uuid nomad job within the cluster
31+
"""
32+
33+
# import os
34+
# import luigi
35+
from luigi.contrib.nomad import NomadJobTask
36+
37+
38+
class PerlPi(NomadJobTask):
39+
40+
name = "pi"
41+
max_retrials = 3
42+
spec_schema = {
43+
"Type": "batch",
44+
"TaskGroups": [{
45+
"Name": "main",
46+
"Tasks": [{
47+
"Name": "pi",
48+
"Driver": "docker",
49+
"Config": {
50+
"image": "perl",
51+
"command": "perl",
52+
"args": ["-Mbignum=bpi", "-wle", "print bpi(2000)"]
53+
},
54+
}]
55+
}]
56+
}
57+
58+
# defining the two functions below allows for dependency checking,
59+
# but isn't a requirement
60+
# def signal_complete(self):
61+
# with self.output().open('w') as output:
62+
# output.write('')
63+
#
64+
# def output(self):
65+
# target = os.path.join("/tmp", "PerlPi")
66+
# return luigi.LocalTarget(target)

0 commit comments

Comments
 (0)