JOBS / LONG RUNNING OPERATIONS SPECS



CASES



REQUIREMENTS

- An endpoint to view jobs in the table
- An endpoint to view logs of jobs
- A db schema (see below)
- biz object callable from other biz objects with following functionality
    - Submit jobs
    - Remove jobs
        - Remove all jobs for object type and id (called when deleting an object)
    - Update status of jobs
    - Log ops of jobs



- OPERATIONS endpoint:
    - GET JOB LIST Check a list of jobs (with rights to do so). Works even when api is locked.
        -  GET /operations returns list of jobs sorted by lastActionDateTime or createdDateTime via query parameter
            - {
                "jobid":"1234",
                "createdDateTime": "2015-06-19T12-01-03.45Z",
                "lastActionDateTime": "2015-06-19T12-01-03.45Z",    //<----determined from log, not stored in AOPSJOB           
                "name":"Send notifications | Import data | Backup | Restore",
                "exclusive":"true/false",
                "status": "sleeping | notstarted | running | succeeded | failed",
                "log":"/operations/log/1234"
                }

- ROUTE: "OPERATIONS" endpoint to get log of long running operation /operations/log/1234
    -    [
            {
                 "DateTime": "2015-06-19T12-01-03.45Z",
                 "Entry": "Imported 4 clients, 3 were duplicates and ignored" 
            },
             {
                 "DateTime": "2015-06-19T12-02-03.45Z",                 
                 "FAILED to import 5 workorders - data format invalid"
            },
             {
                "DateTime": "2015-06-19T12-04-03.45Z",                 
                "Operation completed with errors"
            }
        ]

- FUTURE: delete jobs that have not started yet
- FUTURE: cancel jobs and cancellation token



SCHEMA
=-=-=-=

AOPSJOB
    - jobid long NOT NULL INDEXED UNIQUE (initially I'll use linux epoch when job created, used to tag logs etc, but keeping this open for a change later)   
    - Created  NOT NULL
    - Exclusive NOT NULL bool (true=close api and don't run any other jobs, false=process async and keep api open)
    - StartAfter NOT NULL INDEXED (datetime to start the job, in cases of start now jobs the date will be minvalue)   
    - jobtype enum int NOT NULL of the jobtype which is an enum of all possible job types (i.e. NotifyClosed)
    - ObjectId NULL source of job object id (i.e. workorder id)
    - ObjectType NULL source of job object type (i.e. workorder)
    - descriptive name text NOT NULL for display in UI only, isn't filtered    
    - jobstatus enum int NOT NULL type (one of  "sleeping | notstarted | running | succeeded | failed")   
    - jobinfo text NULL (json string of extra info required for job, maybe the name of an import file or who knows what, anything really can be put in here as long as it's shortish)

AOPSJOBLOG
    - jobid long not null
    - created not null (indexed?  Will be ordered by this a lot but it's the natural order...no?)
    - statustext NOT NULL
