Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add function to get job status #96

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion source/include/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,14 @@ size_t Jobs_GetJobId( const char * message,
const char ** jobId );
/* @[declare_jobs_getjobid] */

size_t Jobs_GetJobStatus( const char * message,
size_t messageLength,
const char ** jobStatus );

size_t Jobs_GetJobVersionNumber( const char * message,
size_t messageLength,
const char ** jobVersionNumber );

/**
* @brief Retrieves the job document from a given message (if applicable)
*
Expand Down Expand Up @@ -1005,4 +1013,4 @@ bool Jobs_IsJobUpdateStatus( const char * topic,
#endif
/* *INDENT-ON* */

#endif /* ifndef JOBS_H_ */
#endif /* ifndef JOBS_H_ */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

48 changes: 47 additions & 1 deletion source/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,52 @@ size_t Jobs_GetJobId( const char * message,
return jobIdLength;
}

size_t Jobs_GetJobStatus( const char * message,
size_t messageLength,
const char ** jobStatus )
{
size_t jobStatusLength = 0U;
JSONStatus_t jsonResult = JSONNotFound;

jsonResult = JSON_Validate( message, messageLength );

if( jsonResult == JSONSuccess )
{
jsonResult = JSON_SearchConst( message,
messageLength,
"execution.status",
CONST_STRLEN( "execution.status" ),
jobStatus,
&jobStatusLength,
NULL );
}

return jobStatusLength;
}

size_t Jobs_GetJobVersionNumber( const char * message,
size_t messageLength,
const char ** jobVersionNumber )
{
size_t jobVersionNumberLength = 0U;
JSONStatus_t jsonResult = JSONNotFound;

jsonResult = JSON_Validate( message, messageLength );

if( jsonResult == JSONSuccess )
{
jsonResult = JSON_SearchConst( message,
messageLength,
"execution.versionNumber",
CONST_STRLEN( "execution.versionNumber" ),
jobVersionNumber,
&jobVersionNumberLength,
NULL );
}

return jobVersionNumberLength;
}

size_t Jobs_GetJobDocument( const char * message,
size_t messageLength,
const char ** jobDoc )
Expand All @@ -941,4 +987,4 @@ size_t Jobs_GetJobDocument( const char * message,
}

return jobDocLength;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an empty line at the bottom of this file?

14 changes: 14 additions & 0 deletions source/otaJobParser/job_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ static JSONStatus_t populateCommonFields( const char * jobDoc,
&( result->fileId ) );
}

if( jsonResult == JSONSuccess )
{
buildIndexedFileQueryString( fileIndex,
"fileType",
8U,
queryString,
&queryStringLength );
jsonResult = searchUintValue( jobDoc,
jobDocLength,
queryString,
queryStringLength,
&( result->fileType ) );
Comment on lines +229 to +238
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that this is standard across all the job documents.
For example, here is a job doc from a job that I recently created:

{
  "afr_ota": {
    "protocols": [
      "MQTT"
    ],
    "streamname": "AFR_OTA-some-stream-name",
    "files": [
      {
        "filepath": "NA",
        "filesize": 624244,
        "fileid": 0,
        "certfile": "sss:00213243",
        "update_data_url": null,
        "auth_scheme": null,
        "sig-sha256-ecdsa": "my-signature-goes-here"
      }
    ]
  }
}

}

if( jsonResult == JSONSuccess )
{
buildIndexedFileQueryString( fileIndex,
Expand Down
Loading