-
Notifications
You must be signed in to change notification settings - Fork 0
jobs
Provides routines to request and sync data on database.
class JobStatus(Enum)Enum to control job status.
Job is queued and waiting to be processed.
Job request failed.
Job request returned item had incorrect fields.
Job with incorrect start date.
Job successfully completed.
def get_label() -> strReturns:
a string label for each status.
@dataclass
class SerieStationData()Data class to receive Series Job data when starting a job.
Station code which data will be requested.
Start date which data will be requested
End date which data will be requested
def get_token() -> Token.TokenAuthenticate and return access token.
Returns:
Valid token for requesition
def check_resource(resource: HidroResource) -> NoneChecks each HidroResource and request/update them.
Arguments:
-
resource: Current Resource to check, insert and update.
Returns:
Nothing.
def check_stations_jobs() -> NoneChecks if there is Stations entries on database. Request all national stations by UF if there isnt.
def check_series_job(job_config: JobConfig) -> NoneChecks an JobConfig. Create jobs if there is no entries and start pending jobs requisition.
def create_series_jobs(stations_data: List[SerieStationData],
job_config: JobConfig) -> NoneCreates Series Jobs for each SerieStationData received for a given JobConfig. Preprocess all years from "Start Date" to "End Date" that will become a job request.
def trigger_job(job_config: JobConfig) -> NoneTriggers an Thread Worker for each pending or falied job entrie in DB for a given JobConfig.
def handle_job(job: HidroJob, job_config: JobConfig) -> NoneRequest data of an HidroJob. Validate data on success return, and convert to ORM model before writing on Queue.
def db_writer() -> NoneSingle Writer Thread running during an Job. Consumes an Queue writen by each worker and write data in batches.
def write_data(job_config: JobConfig, jobs: List[HidroJob],
hidro_data: dict) -> floatInsert data into DB and update the jobs as well.
def validate_data(job_config: JobConfig, items: dict,
job: HidroJob) -> (HidroJob, dict)Validate returned data by the API.
def data_to_model_orm(job_config: JobConfig, hidro_data: dict)Convert returned data by the API into the correspondent ORM Model of the job.