Support node, deno, & python runtimes for timer functions
This commit is contained in:
@@ -376,7 +376,7 @@ def toggle(function_id):
|
|||||||
timer_functions = db.execute("""
|
timer_functions = db.execute("""
|
||||||
SELECT id, name, code, environment, trigger_type,
|
SELECT id, name, code, environment, trigger_type,
|
||||||
frequency_minutes, run_date, next_run,
|
frequency_minutes, run_date, next_run,
|
||||||
last_run, enabled, invocation_count
|
last_run, enabled, invocation_count, runtime
|
||||||
FROM timer_functions
|
FROM timer_functions
|
||||||
WHERE user_id = %s
|
WHERE user_id = %s
|
||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ const Editor = {
|
|||||||
run_date: this.triggerType === "date" ? this.runDate : null,
|
run_date: this.triggerType === "date" ? this.runDate : null,
|
||||||
is_enabled: this.isEnabled,
|
is_enabled: this.isEnabled,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
|
runtime: this.runtime,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ history_url=url_for('timer.history', function_id=function_id)) }}
|
|||||||
showDeleteButton: true,
|
showDeleteButton: true,
|
||||||
isTimer: true,
|
isTimer: true,
|
||||||
showTimerSettings: true,
|
showTimerSettings: true,
|
||||||
|
frequencyMinutes: {{ timer_function.frequency_minutes }},
|
||||||
cancelUrl: "{{ url_for('timer.overview') }}",
|
cancelUrl: "{{ url_for('timer.overview') }}",
|
||||||
generateUrl: "{{ url_for('llm.generate_script') }}",
|
generateUrl: "{{ url_for('llm.generate_script') }}",
|
||||||
showPublicToggle: false,
|
showPublicToggle: false,
|
||||||
|
|||||||
@@ -35,7 +35,11 @@ title='New Timer Function')
|
|||||||
isTimer: true,
|
isTimer: true,
|
||||||
showTimerSettings: true,
|
showTimerSettings: true,
|
||||||
triggerType: 'interval',
|
triggerType: 'interval',
|
||||||
frequencyMinutes: 60
|
frequencyMinutes: 60,
|
||||||
|
runtime: 'node',
|
||||||
|
showPublicToggle: false,
|
||||||
|
showLogRequestToggle: false,
|
||||||
|
showLogResponseToggle: false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -41,6 +41,10 @@
|
|||||||
hx-get="{{ url_for('timer.edit', function_id=function.id) }}" hx-target="#container"
|
hx-get="{{ url_for('timer.edit', function_id=function.id) }}" hx-target="#container"
|
||||||
hx-swap="innerHTML" hx-push-url="true">
|
hx-swap="innerHTML" hx-push-url="true">
|
||||||
<span class="font-medium text-gray-900 dark:text-white">{{ function.name }}</span>
|
<span class="font-medium text-gray-900 dark:text-white">{{ function.name }}</span>
|
||||||
|
<span
|
||||||
|
class="bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300 text-xs font-medium px-2.5 py-0.5 rounded-full uppercase">
|
||||||
|
{{ function.runtime }}
|
||||||
|
</span>
|
||||||
<span
|
<span
|
||||||
class="bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300 text-xs font-medium px-2.5 py-0.5 rounded-full">
|
class="bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300 text-xs font-medium px-2.5 py-0.5 rounded-full">
|
||||||
{{ function.invocation_count }}
|
{{ function.invocation_count }}
|
||||||
|
|||||||
21
worker.py
21
worker.py
@@ -19,7 +19,11 @@ init_app(app)
|
|||||||
# Initialize scheduler
|
# Initialize scheduler
|
||||||
scheduler = APScheduler()
|
scheduler = APScheduler()
|
||||||
TIMER_CHECK_INTERVAL = int(os.environ.get('TIMER_CHECK_INTERVAL_MINUTES', 1)) # Change back to 5 minutes
|
TIMER_CHECK_INTERVAL = int(os.environ.get('TIMER_CHECK_INTERVAL_MINUTES', 1)) # Change back to 5 minutes
|
||||||
API_URL = os.environ.get('API_URL', 'http://isolator.web:5000/execute')
|
|
||||||
|
# Runtime-specific API URLs matching app.py configuration
|
||||||
|
NODE_API_URL = os.environ.get('NODE_API_URL', 'http://isolator.web:5000/execute')
|
||||||
|
DENO_API_URL = os.environ.get('DENO_API_URL', 'http://deno-isolator.web:5000/execute')
|
||||||
|
PYTHON_API_URL = os.environ.get('PYTHON_API_URL', 'http://python-isolator.web:5000/execute')
|
||||||
|
|
||||||
async def execute_timer_function_async(timer_function):
|
async def execute_timer_function_async(timer_function):
|
||||||
"""
|
"""
|
||||||
@@ -30,9 +34,18 @@ async def execute_timer_function_async(timer_function):
|
|||||||
environment = timer_function['environment']
|
environment = timer_function['environment']
|
||||||
name = timer_function['name']
|
name = timer_function['name']
|
||||||
version_number = timer_function['version_number']
|
version_number = timer_function['version_number']
|
||||||
|
runtime = timer_function.get('runtime', 'node') # Default to node if not specified
|
||||||
|
|
||||||
|
# Select the appropriate API URL based on runtime
|
||||||
|
if runtime == 'deno':
|
||||||
|
api_url = DENO_API_URL
|
||||||
|
elif runtime == 'python':
|
||||||
|
api_url = PYTHON_API_URL
|
||||||
|
else:
|
||||||
|
api_url = NODE_API_URL
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.post(API_URL, json={
|
async with session.post(api_url, json={
|
||||||
'code': code,
|
'code': code,
|
||||||
'request': {'method': 'TIMER'},
|
'request': {'method': 'TIMER'},
|
||||||
'environment': environment,
|
'environment': environment,
|
||||||
@@ -93,7 +106,7 @@ def check_and_execute_timer_functions():
|
|||||||
SELECT
|
SELECT
|
||||||
id, name, code, environment, version_number,
|
id, name, code, environment, version_number,
|
||||||
trigger_type, frequency_minutes, run_date,
|
trigger_type, frequency_minutes, run_date,
|
||||||
next_run, enabled,
|
next_run, enabled, runtime,
|
||||||
EXTRACT(EPOCH FROM (NOW() - next_run)) as seconds_since_next_run
|
EXTRACT(EPOCH FROM (NOW() - next_run)) as seconds_since_next_run
|
||||||
FROM timer_functions
|
FROM timer_functions
|
||||||
WHERE enabled = true
|
WHERE enabled = true
|
||||||
@@ -139,4 +152,4 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
asyncio.get_event_loop().run_forever()
|
asyncio.get_event_loop().run_forever()
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
pass
|
pass
|
||||||
Reference in New Issue
Block a user