Skip to content

Commit

Permalink
job/job, job/task: Provide immediate TaskParam
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Jung <a.jung@lancs.ac.uk>
  • Loading branch information
nderjung committed Dec 17, 2020
1 parent 513c807 commit 98854e3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
22 changes: 11 additions & 11 deletions job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ type RuntimeConfig struct {
Cpus []int
}

func parseParamStr(param *JobParam) ([]*TaskParam, error) {
var params []*TaskParam
func parseParamStr(param *JobParam) ([]TaskParam, error) {
var params []TaskParam

if len(param.Only) > 0 {
for _, val := range param.Only {
params = append(params, &TaskParam{
params = append(params, TaskParam{
Name: param.Name,
Type: param.Type,
Value: val,
})
}
} else if len(param.Default) > 0 {
params = append(params, &TaskParam{
params = append(params, TaskParam{
Name: param.Name,
Type: param.Type,
Value: param.Default,
Expand All @@ -135,13 +135,13 @@ func parseParamStr(param *JobParam) ([]*TaskParam, error) {
return params, nil
}

func parseParamInt(param *JobParam) ([]*TaskParam, error) {
var params []*TaskParam
func parseParamInt(param *JobParam) ([]TaskParam, error) {
var params []TaskParam

// Parse values in only
if len(param.Only) > 0 {
for _, val := range param.Only {
params = append(params, &TaskParam{
params = append(params, TaskParam{
Name: param.Name,
Type: param.Type,
Value: val,
Expand Down Expand Up @@ -180,7 +180,7 @@ func parseParamInt(param *JobParam) ([]*TaskParam, error) {
// Use iterative step
if len(param.StepMode) == 0 || param.StepMode == "increment" {
for i := min; i <= max; i += step {
params = append(params, &TaskParam{
params = append(params, TaskParam{
Name: param.Name,
Type: param.Type,
Value: strconv.Itoa(i),
Expand All @@ -190,7 +190,7 @@ func parseParamInt(param *JobParam) ([]*TaskParam, error) {
// Use exponential step
} else if param.StepMode == "power" {
for i := min; i <= max; math.Pow(float64(step), float64(i)) {
params = append(params, &TaskParam{
params = append(params, TaskParam{
Name: param.Name,
Type: param.Type,
Value: strconv.Itoa(i),
Expand All @@ -206,7 +206,7 @@ func parseParamInt(param *JobParam) ([]*TaskParam, error) {


} else if len(param.Default) > 0 {
params = append(params, &TaskParam{
params = append(params, TaskParam{
Name: param.Name,
Type: param.Type,
Value: param.Default,
Expand All @@ -216,7 +216,7 @@ func parseParamInt(param *JobParam) ([]*TaskParam, error) {
return params, nil
}

func enumerateTaskParams(param *JobParam) ([]*TaskParam, error) {
func paramPermutations(param *JobParam) ([]TaskParam, error) {
switch t := param.Type; t {
case "string":
return parseParamStr(param)
Expand Down
44 changes: 44 additions & 0 deletions job/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package job
// SPDX-License-Identifier: BSD-3-Clause
//
// Authors: Alexander Jung <a.jung@lancs.ac.uk>
//
// Copyright (c) 2020, Lancaster University. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

type TaskParam struct {
Name string
Type string
Value string
}

// Task is the specific iterated configuration
type Task struct {
Params []TaskParam
Inputs *[]Input
Outputs *[]Output
}

0 comments on commit 98854e3

Please sign in to comment.