I want to expose APIs in python for my workload automation software. I have a Job class as defined/outlined below. Instance of this job class represents a particular Job run. Job can have multiple checkpoints and each checkpoint can have multiple commands.
Job - JobName - [JobCheckpoint] - StartTime - EndTime - Status - ... JobCheckpoint - JobCheckpointName - [JobCommand] - StartTime - EndTime - Status - ... JobCommand - JobCommandName - [Command] - StartTime - EndTime - Status - ...
I want user APIs for satisfying following use-cases:
- Ability to query Jobs given a criteria (e.g. return jobs that ran in a given duration, return jobs in failed state, return checkpoints/commands of a particular job and many more...).
- Ability to create and run jobs using Python API.
- Ability to take control actions like rerun already ran job, kill running job etc.
I am thinking of providing following method in my user API.
get_jobs(Filter) - This serves/solves use-case#1
I am not sure how best Filter class can be designed. The goal is to provide intuitive and powerful API's to users.
I am not sure how should I solve use-case #2 and #3 above. I have couple of solutions in my mind but I am not sure which one is best.
Solution#1. For creating Jobs, users can directly instantiate Object of class Job. I will provide methods in Job Model class itself for running and re-running Job. Users will create instance of Job class and call methods (run, rerun, kill etc) on Job object.
Solution#2. Along with get_job API, expose separate APIs for control actions like run and rerun in user interface.
get_job(Filter) run_job(Job) rerun_job(Job) ...
What if in future I want to support many more control actions on Job object (for e.x. hold, resume etc.). If I go with solution#2, I will end up creating lots of methods in user API. If I go with solution#1, I am not sure if Job class can be called as model class.
I am not sure which of the approach mentioned above is better and why? Or there is some other way I should think of.