Skip to content

Commit

Permalink
feat: adding scheduling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Jun 20, 2024
1 parent 6fdfa55 commit 4cb1800
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cdk/v2/destinations/clicksend/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ steps:
name : String(.properties.name),
body : String(.properties.body),
from : $.getDestinationExternalID(^.message,'CLICKSEND_SENDER_EMAIL') || ^.destination.Config.defaultSenderEmail,
schedule : .properties.schedule,
schedule : $.deduceSchedule(.properties.schedule,{{{{$.getGenericPaths("timestamp")}}}}, ^.destination.Config)
});
console.log(JSON.stringify(.destination.Config));
console.log(.destination.Config.defaultSenderEmail);
Expand All @@ -78,7 +78,7 @@ steps:
to: {{{{$.getGenericPaths("phone")}}}},
body: .properties.body,
source: .properties.source || ^.destination.Config.defaultSource,
schedule: .properties.schedule,
schedule: $.deduceSchedule(.properties.schedule, ^.destination.Config),
custom_string: .properties.custom_string,
country: {{{{$.getGenericPaths("country")}}}},
from_email: .properties.from_email
Expand Down
22 changes: 22 additions & 0 deletions src/cdk/v2/destinations/clicksend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ const validateTrackSMSCampaignPayload = (payload) => {
}
};

const deduceSchedule = (eventLevelSchedule, timestamp, destConfig) => {
if (isDefinedAndNotNullAndNotEmpty(eventLevelSchedule) && !Number.isNaN(destConfig)) {
return eventLevelSchedule;
}
const { defaultCampaignScheduleUnit, defaultCampaignSchedule } = destConfig;
// Parse the input timestamp into a Date object
const date = new Date(timestamp);

// Check the delta unit and add the appropriate amount of time
if (defaultCampaignScheduleUnit === 'day') {
date.setDate(date.getDate() + defaultCampaignSchedule);
} else if (defaultCampaignScheduleUnit === 'minute') {
date.setMinutes(date.getMinutes() + defaultCampaignSchedule);
} else {
throw new Error("Invalid delta unit. Use 'day' or 'minute'.");
}

// Return the future date as a UNIX timestamp in seconds
return Math.floor(date.getTime() / 1000);
};

const mergeMetadata = (batch) => {
const metadata = [];
batch.forEach((event) => {
Expand Down Expand Up @@ -144,4 +165,5 @@ module.exports = {
getEndIdentifyPoint,
validateIdentifyPayload,
validateTrackSMSCampaignPayload,
deduceSchedule,
};

0 comments on commit 4cb1800

Please sign in to comment.