(path string, processLimit uint, runtimeLimit time.Duration)
| 26 | } |
| 27 | |
| 28 | func MakeShellScriptPricing(path string, processLimit uint, runtimeLimit time.Duration) (BidPricingStrategy, error) { |
| 29 | if len(path) == 0 { |
| 30 | return nil, errPathEmpty |
| 31 | } |
| 32 | if processLimit == 0 { |
| 33 | return nil, errProcessLimitZero |
| 34 | } |
| 35 | if runtimeLimit == 0 { |
| 36 | return nil, errProcessRuntimeLimitZero |
| 37 | } |
| 38 | |
| 39 | result := shellScriptPricing{ |
| 40 | path: path, |
| 41 | processLimit: make(chan int, processLimit), |
| 42 | runtimeLimit: runtimeLimit, |
| 43 | } |
| 44 | |
| 45 | // Use the channel as a semaphore to limit the number of processes created for computing bid processes |
| 46 | // Most platforms put a limit on the number of processes a user can open. Even if the limit is high |
| 47 | // it isn't a good idea to open thousands of processes. |
| 48 | for i := uint(0); i != processLimit; i++ { |
| 49 | result.processLimit <- 0 |
| 50 | } |
| 51 | |
| 52 | return result, nil |
| 53 | } |
| 54 | |
| 55 | func parseCPU(res *rtypes.CPU) uint64 { |
| 56 | return res.Units.Val.Uint64() |
no outgoing calls