# simplejob
This is simple job execution module.
# Overview
You can execute job with relationship using this module. Job execution time can be delayed until other jobs are finished.
# Getting Started
## install package
```
pip install simplejob
```
## Run with the JobManager class
If you want to run a related many jobs, use the JobManager class.
At first, import the JobManager from this module.
```
from simplejob.simplejob import SimpleJobManager
```
Prepare a job context consisting of job parameters and pass it as an argument to JobManager.entry().
+ id ... Job ID (arbitrary name, if omitted, the base name of the first command line argument)
+ commandLine ... command to execute and command line parameters
* Waits ... List of job IDs waiting to run
```
jobContexts = [
{ "id": "hoge", "commandLine": r"timeout /t 1 /nobreak" },
{ "id": "piyo", "commandLine": r"timeout /t 3 /nobreak", "waits": [ "hoge" ] },
{ "id": "fuga", "commandLine": r"timeout /t 5 /nobreak", "waits": [ "hoge" ] },
{ "id": "moga", "commandLine": r"timeout /t 2 /nobreak", "waits": [ "piyo", "fuga" ] },
]
jobManager = SimpleJobManager()
jobManager.entry(jobContexts)
```
Run all jobs through JobManager.runAllReadyJobs() until all jobs are finished or an error occurs. If necessary, call an interval timer in the loop. The example calls a 1 second interval timer.
```
while True:
jobManager.runAllReadyJobs()
if jobManager.errorOccurred():
print("error occurred")
jobManager.join()
break
if jobManager.completed():
break
time.sleep(1)
```
It can be written on a single line using run(). If error occred in the run(), Raise CalledJobException.
```
jobManager.run()
```
### report
You can output the execution result as a report by calling report(). Returns an empty result for jobs that have not run.
Example for SimpleJobManager.report()
```
{
"results": [
{
"hoge": {
"runnigStatus": "Completed",
"exitCode": 0,
"retried": null,
"commandLine": "timeout /t 1 /nobreak",
"startDateTime": "2023/05/27 05:42:16.595910",
"finishDateTime": "2023/05/27 05:42:17.172984",
"elapsedTime": "00:00:00.580679"
}
},
{
"piyo": {
"runnigStatus": "Completed",
"exitCode": 0,
"retried": null,
"commandLine": "timeout /t 3 /nobreak",
"startDateTime": "2023/05/27 05:42:17.589688",
"finishDateTime": "2023/05/27 05:42:20.131554",
"elapsedTime": "00:00:02.537245"
}
},
{
"fuga": {
"runnigStatus": "Completed",
"exitCode": 0,
"retried": null,
"commandLine": "timeout /t 1 /nobreak",
"startDateTime": "2023/05/27 05:42:17.597681",
"finishDateTime": "2023/05/27 05:42:18.177357",
"elapsedTime": "00:00:00.584966"
}
},
{
"moga": {
"runnigStatus": "Completed",
"exitCode": 0,
"retried": null,
"commandLine": "timeout /t 2 /nobreak",
"startDateTime": "2023/05/27 05:42:20.636437",
"finishDateTime": "2023/05/27 05:42:22.192478",
"elapsedTime": "00:00:01.556920"
}
}
]
}
```
### Retry on timed out
If the job fails by timed out, it can be retried. The retry parameters are as follows.Retry parameters can be set for individual jobs.
+ retry ... Retry count (default is 0, no retry)
+ timeout ... Number of seconds to timeout the job (default is None, no timeout)
+ delay ... number of seconds to delay the job on retry (default 0, no delay)
+ backkoff ... power to back off the retry interval (default 1)
The report for a failed retry is shown below.
```
{
"runnigStatus": "RetryOut",
"exitCode": null,
"retried": 1,
"commandLine": "timeout /t 2 /nobreak",
"startDateTime": "2023/05/18 21:47:38.528989",
"finishDateTime": "2023/05/18 21:47:43.594701",
"elapsedTime": "00:00:05.65712"
}
```
### rerun
After the cause of the error has been resolved, the job can be rerun using rerun().
```
jobManager.rerun()
```
## Output the job log
To output logs, specify the logOutputDirectory parameter to constructor of SimpleJobManager class. The log file name is the job id with a "log" extension.
```
jobManager = SimpleJobManager(r"C:\temp\log")
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Hajime-Saitou/simplejob",
"name": "simplejob",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "batch,job",
"author": "Hajime Saito",
"author_email": "g.hajime.saitou@gmail.com",
"download_url": "",
"platform": null,
"description": "# simplejob\r\nThis is simple job execution module.\r\n\r\n# Overview\r\nYou can execute job with relationship using this module. Job execution time can be delayed until other jobs are finished.\r\n\r\n# Getting Started\r\n\r\n## install package\r\n\r\n```\r\npip install simplejob\r\n```\r\n\r\n## Run with the JobManager class\r\n\r\nIf you want to run a related many jobs, use the JobManager class.\r\n\r\nAt first, import the JobManager from this module.\r\n\r\n```\r\nfrom simplejob.simplejob import SimpleJobManager\r\n```\r\n\r\nPrepare a job context consisting of job parameters and pass it as an argument to JobManager.entry().\r\n\r\n+ id ... Job ID (arbitrary name, if omitted, the base name of the first command line argument)\r\n+ commandLine ... command to execute and command line parameters\r\n* Waits ... List of job IDs waiting to run\r\n\r\n```\r\njobContexts = [\r\n { \"id\": \"hoge\", \"commandLine\": r\"timeout /t 1 /nobreak\" },\r\n { \"id\": \"piyo\", \"commandLine\": r\"timeout /t 3 /nobreak\", \"waits\": [ \"hoge\" ] },\r\n { \"id\": \"fuga\", \"commandLine\": r\"timeout /t 5 /nobreak\", \"waits\": [ \"hoge\" ] },\r\n { \"id\": \"moga\", \"commandLine\": r\"timeout /t 2 /nobreak\", \"waits\": [ \"piyo\", \"fuga\" ] },\r\n]\r\njobManager = SimpleJobManager()\r\njobManager.entry(jobContexts)\r\n```\r\n\r\nRun all jobs through JobManager.runAllReadyJobs() until all jobs are finished or an error occurs. If necessary, call an interval timer in the loop. The example calls a 1 second interval timer.\r\n\r\n```\r\nwhile True:\r\n jobManager.runAllReadyJobs()\r\n if jobManager.errorOccurred():\r\n print(\"error occurred\")\r\n jobManager.join()\r\n break\r\n\r\n if jobManager.completed():\r\n break\r\n\r\n time.sleep(1)\r\n```\r\n\r\nIt can be written on a single line using run(). If error occred in the run(), Raise CalledJobException.\r\n\r\n```\r\njobManager.run()\r\n```\r\n\r\n### report\r\n\r\nYou can output the execution result as a report by calling report(). Returns an empty result for jobs that have not run.\r\n\r\nExample for SimpleJobManager.report()\r\n\r\n```\r\n{\r\n \"results\": [\r\n {\r\n \"hoge\": {\r\n \"runnigStatus\": \"Completed\",\r\n \"exitCode\": 0,\r\n \"retried\": null,\r\n \"commandLine\": \"timeout /t 1 /nobreak\",\r\n \"startDateTime\": \"2023/05/27 05:42:16.595910\",\r\n \"finishDateTime\": \"2023/05/27 05:42:17.172984\",\r\n \"elapsedTime\": \"00:00:00.580679\"\r\n }\r\n },\r\n {\r\n \"piyo\": {\r\n \"runnigStatus\": \"Completed\",\r\n \"exitCode\": 0,\r\n \"retried\": null,\r\n \"commandLine\": \"timeout /t 3 /nobreak\",\r\n \"startDateTime\": \"2023/05/27 05:42:17.589688\",\r\n \"finishDateTime\": \"2023/05/27 05:42:20.131554\",\r\n \"elapsedTime\": \"00:00:02.537245\"\r\n }\r\n },\r\n {\r\n \"fuga\": {\r\n \"runnigStatus\": \"Completed\",\r\n \"exitCode\": 0,\r\n \"retried\": null,\r\n \"commandLine\": \"timeout /t 1 /nobreak\",\r\n \"startDateTime\": \"2023/05/27 05:42:17.597681\",\r\n \"finishDateTime\": \"2023/05/27 05:42:18.177357\",\r\n \"elapsedTime\": \"00:00:00.584966\"\r\n }\r\n },\r\n {\r\n \"moga\": {\r\n \"runnigStatus\": \"Completed\",\r\n \"exitCode\": 0,\r\n \"retried\": null,\r\n \"commandLine\": \"timeout /t 2 /nobreak\",\r\n \"startDateTime\": \"2023/05/27 05:42:20.636437\",\r\n \"finishDateTime\": \"2023/05/27 05:42:22.192478\",\r\n \"elapsedTime\": \"00:00:01.556920\"\r\n }\r\n }\r\n ]\r\n}\r\n```\r\n\r\n### Retry on timed out\r\nIf the job fails by timed out, it can be retried. The retry parameters are as follows.Retry parameters can be set for individual jobs.\r\n\r\n+ retry ... Retry count (default is 0, no retry)\r\n+ timeout ... Number of seconds to timeout the job (default is None, no timeout)\r\n+ delay ... number of seconds to delay the job on retry (default 0, no delay)\r\n+ backkoff ... power to back off the retry interval (default 1)\r\n\r\nThe report for a failed retry is shown below.\r\n\r\n```\r\n{\r\n \"runnigStatus\": \"RetryOut\",\r\n \"exitCode\": null,\r\n \"retried\": 1,\r\n \"commandLine\": \"timeout /t 2 /nobreak\",\r\n \"startDateTime\": \"2023/05/18 21:47:38.528989\",\r\n \"finishDateTime\": \"2023/05/18 21:47:43.594701\",\r\n \"elapsedTime\": \"00:00:05.65712\"\r\n}\r\n```\r\n\r\n### rerun\r\n\r\nAfter the cause of the error has been resolved, the job can be rerun using rerun().\r\n\r\n```\r\njobManager.rerun()\r\n```\r\n\r\n## Output the job log\r\n\r\nTo output logs, specify the logOutputDirectory parameter to constructor of SimpleJobManager class. The log file name is the job id with a \"log\" extension.\r\n\r\n```\r\njobManager = SimpleJobManager(r\"C:\\temp\\log\")\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Simple Batch job executor",
"version": "0.0.6",
"project_urls": {
"Homepage": "https://github.com/Hajime-Saitou/simplejob",
"Source": "https://github.com/Hajime-Saitou/simplejob"
},
"split_keywords": [
"batch",
"job"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "151f389548fa3bd6bc9e38810194480053817b9f1f0e62e598e05dea1ff1944d",
"md5": "889ad7de8e414c63b4490caac317d7b2",
"sha256": "b2a339cf68f51b287739ce9f28c353294579328ac34ca2372fdf506978efdc45"
},
"downloads": -1,
"filename": "simplejob-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "889ad7de8e414c63b4490caac317d7b2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7312,
"upload_time": "2023-05-28T21:10:52",
"upload_time_iso_8601": "2023-05-28T21:10:52.614913Z",
"url": "https://files.pythonhosted.org/packages/15/1f/389548fa3bd6bc9e38810194480053817b9f1f0e62e598e05dea1ff1944d/simplejob-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-28 21:10:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Hajime-Saitou",
"github_project": "simplejob",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "simplejob"
}