Comments (13)
In the backend a call of this form will be made each time a job is executed:
async with httpx.AsyncClient() as client:
resp = await client.get( # action can be any HTTP verb (GET, PUT, POST, etc) set in the job config
url, # from the job config
headers, # from the job config
)
save_job_execution(resp.status_code, resp.text())
from scheduler.
Any suggestions on where to put the dependency, would be helpful.
- please open a PR on the
lnbits/lnbits
repo with the new dependency - this PR should be merged before releasing the extension
as the crontab script needs to call the API and does not inherit the LNBits environment
- relative paths should be supported in the front-end
- if a relative path is used then the back-end must add
http://${HOST}/${PORT}
Also the user must set the username that has access to system /usr/bin/crontab
- why is a OS user required? what happens on non-linux system?
from scheduler.
Do we want to enable the username?
- we want to keep this as simple as possible for the users that install the extension
- it looks like the
username
option is not mandatory, that is good
I know for OSX, I needed it.
- you mean you had to take extra steps in order to use the lib?
- we should limit/automate that as much as possible
from scheduler.
OK I am testing this with both Ubuntu and OSX. Will try to have everything working with latest 0.11 this weekend. (this week has been a bit busy)
from scheduler.
HOST=127.0.0.1 PORT=5000* data can also be passes to the job in the `comment` field (or something similar), right?
yes I know that the HOST/PORT is in the LNBits .env, but that cron script unfortunately runs outside of the LNBits environment as its called by system crontab which doesn't inherit the LNBits environment.
I can pass the HOST/PORT in, just like the job ID and adminKey is passed in right now (this is testnet example).
Perhaps this is better way to do it.
Ok I will test and get back to you. Thanks @motorina0
from scheduler.
tested with sqlitedb only so far, no postgres
from scheduler.
@motorina0 OK. I think the directions are clear.
The python-crontabs module would store the X-API-Key values as environment variables in the crontab file, so each individual job will have its own set of env vars.
Assuming there is no need for global env vars, I'll remove the Global Environment variables box that is currently at the bottom of the extension right now.
Please do let me know if incorrect! thanks.
from scheduler.
Regarding running jobs:
- there should be only one command file
- the
job_id
is passed to the command file - the command file fetches the full job details from the DB and executes the HTTP call
Adapting a simple example from here:
from crontab import CronTab
cron = CronTab(user='username')
job = cron.new(command='python lnbits/utils/cron-job.py') # pass the job_id param somehow
job.minute.every(1)
cron.write()
cron-job.py
:
# imports go here
# extract job_id param
# query DB for job
async with httpx.AsyncClient() as client:
resp = await client.get( # action can be any HTTP verb (GET, PUT, POST, etc) set in the job config
url, # from the job config
headers, # from the job config
)
save_job_execution(resp.status_code, resp.text())
Note:
- I'm not sure if the job creation example is the latest and greatest way of starting jobs with the
crontab
extension. - its just to illustrate the flow
from scheduler.
Working on testing the extension install now.
Any suggestions on where to put the dependency, would be helpful.
Right now the python-crontab dependency is in the requirements.txt file but the user has to install it themselves, its not on the LNBits main poetry toml.
Also the user must set the username that has access to system /usr/bin/crontab
and they need to specify their LNBITS Install, as the crontab script needs to call the API and does not inherit the LNBits environment. I've put these two variables in a .env file, but there is no UI to edit this directly right now.
Implemented as you suggested using a run_cron_job.py script.
from scheduler.
According to the docs, there are three ways to do it, with Linux.
One of the ways requires the username.
Do we want to enable the username? I know for OSX, I needed it.
from scheduler.
* if a relative path is used then the back-end must add `http://${HOST}/${PORT}`
Regarding - I have this script running when the cron job is triggered but is does not have the LNBits environment, I put it in as an env variable in .env but if you have a better way of accessing it, please suggest!
Line 20 in 2ceb03e
extension updated to allow for LNBits v0.11 but still need to do more testing.
from scheduler.
Regarding - I have this script running when the cron job is triggered but is does not have the LNBits environment, I put it in as an env variable in .env but if you have a better way of accessing it, please suggest!
.env
file has these properties:
HOST=127.0.0.1
PORT=5000
- data can also be passes to the job in the
comment
field (or something similar), right?
from scheduler.
OK I fixed the above, made a release. It should be working with basic functionality now, validation can improve but please have a look. https://github.com/bitkarrot/scheduler/releases/tag/v0.0.9, @motorina0
from scheduler.
Related Issues (16)
- rename everything to scheduler HOT 1
- convert to proper unit test.
- set environment variables in dialog box HOT 1
- frontend crontab validation + feature HOT 1
- fix start/stop job on UI HOT 1
- Add logging to scheduler HOT 1
- API end points to command HOT 1
- clean up artifacts from copied ext HOT 1
- [Future request]: change logo
- test project1
- [Bug] refresh page - job status HOT 1
- add option to run local script
- [Feature] add multistage requests
- get rid of raw in templates.
- Failed to install extension scheduler (v0.1.1). 500 INTERNAL SERVER ERROR HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scheduler.