NDuell
October 3, 2024, 1:40am
1
Has anyone figured out how to trigger a flow at regular intervals, ie 5 minutes, but this should only run between certain time windows, ie between 12am and 5am?
I can’t seem to work this out with the pieces available, and there seems to be no queries about this in the community.
You can use the cron expression, the last item. I wrote an html standalone editor to create cron expressions. Copy the code below and save it to a local file eg cronBuilder.html. It will do what you want and create the cron entry you need for the activepiece schedule.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Standalone Cron Expression Generator</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 800px;
margin: auto;
background: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
}
label {
display: block;
margin-top: 10px;
}
input[type="text"], select {
width: 100%;
padding: 8px;
margin-top: 5px;
}
.checkbox-group {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 5px;
}
.checkbox-group label {
display: flex;
align-items: center;
}
.result {
margin-top: 20px;
padding: 10px;
background-color: #e9e9e9;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Cron Expression Generator</h1>
<div>
<label for="minutes">Minutes:</label>
<input type="text" id="minutes" placeholder="e.g. * or */5 or 0,30">
</div>
<div>
<label for="hours">Hours:</label>
<input type="text" id="hours" placeholder="e.g. * or */2 or 9-17">
</div>
<div>
<label for="dayOfMonth">Day of Month:</label>
<input type="text" id="dayOfMonth" placeholder="e.g. * or 1-15 or 1,15">
</div>
<div>
<label>Month:</label>
<div class="checkbox-group" id="monthGroup"></div>
</div>
<div>
<label>Day of Week:</label>
<div class="checkbox-group" id="dayOfWeekGroup"></div>
</div>
<div class="result">
<strong>Generated Cron Expression:</strong>
<p id="cronResult"></p>
</div>
</div>
<script>
const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
const daysOfWeek = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
function createCheckboxes(elementId, options) {
const container = document.getElementById(elementId);
options.forEach((option, index) => {
const label = document.createElement('label');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.value = index;
checkbox.id = `${elementId}-${index}`;
label.appendChild(checkbox);
label.appendChild(document.createTextNode(option));
container.appendChild(label);
});
}
createCheckboxes('monthGroup', months);
createCheckboxes('dayOfWeekGroup', daysOfWeek);
function getSelectedValues(elementId) {
const checkboxes = document.querySelectorAll(`#${elementId} input[type="checkbox"]:checked`);
return Array.from(checkboxes).map(cb => cb.value);
}
function generateCronExpression() {
const minutes = document.getElementById('minutes').value || '*';
const hours = document.getElementById('hours').value || '*';
const dayOfMonth = document.getElementById('dayOfMonth').value || '*';
const selectedMonths = getSelectedValues('monthGroup');
const selectedDaysOfWeek = getSelectedValues('dayOfWeekGroup');
const month = selectedMonths.length > 0 ? selectedMonths.map(m => parseInt(m) + 1).join(',') : '*';
const dayOfWeek = selectedDaysOfWeek.length > 0 ? selectedDaysOfWeek.join(',') : '?';
const cronExpression = `${minutes} ${hours} ${dayOfMonth} ${month} ${dayOfWeek}`;
document.getElementById('cronResult').textContent = cronExpression;
}
// Add event listeners
document.getElementById('minutes').addEventListener('input', generateCronExpression);
document.getElementById('hours').addEventListener('input', generateCronExpression);
document.getElementById('dayOfMonth').addEventListener('input', generateCronExpression);
document.querySelectorAll('#monthGroup input, #dayOfWeekGroup input').forEach(checkbox => {
checkbox.addEventListener('change', generateCronExpression);
});
// Initial generation
generateCronExpression();
</script>
</body>
</html>