Announcement

Collapse
No announcement yet.

How to send multiple files at different schedule time within one channel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to send multiple files at different schedule time within one channel

    Hi folks,

    I'm a newbie here. So I have two files need to be scheduled deliver at a different times. Is is doable to accomplish this within one channel?

    For example, I have EMPLOYEE.csv to be scheduled on the 1st of each month. And I have another file PHYSICIAN.csv to be scheduled on the 15th of each month.

    I can build two separate channels: one for EMPLOYEE and one for PHYSICIAN, and we're all done. But I want to know if it is possible to combine both EMPLOYEE and PHYSICIAN in just "one" channel so that on the 1st, it will send EMPLOYEE.csv to the customer. And on the 15th, it will send PHYSICIAN.csv to customer.

    Thank you. I really appreciated

  • #2
    Yes. Create a file reader that reads both files and in the filter

    if(file == customer.csv and date == 1st)
    {
    true;
    }
    else if(file ==pharmacy.csv and date == 15th)
    {
    true;
    }
    else
    {
    false;
    }

    Comment


    • #3
      That might work, but there are risks with doing it that way.

      You'll always be reading in both files, even if you only process one of them. If you do any move or delete operations after reading the file they will apply to the filtered files as well.

      You could get around that by calling an object that dynamically generates the filename filter based on the current date.

      Try this in your channel deploy script (modify as necessary)
      Code:
      function createFilenameProvider() {
      	function getName(dayOfMonth) {
      		if (dayOfMonth >= 15) return 'PHYSICIAN.csv';
      		return 'EMPLOYEE.csv';
      	}
      
      	function toString() {
      		return getName(java.time.LocalDate.now().dayOfMonth);
      	}
      
      	return new JavaAdapter(java.lang.Object, {
      		getName: getName,
      		toString: toString
      	});
      }
      
      // create instance and put in globalChannelMap
      $gc('nameProvider', createFilenameProvider());
      Then use ${nameProvider} for your Filename Filter Pattern (this will implicitly call the object's toString method.) Schedule with a cron type that only runs at the time you want on the 1st and 15th. This would run at 3am on the 1st and 15th of every month.
      Code:
      0 0 3 1,15 * ?
      It's set up to return EMPLOYEE.csv if run from the 1st through the 14th of the month, and PHYSICIAN.csv on the 15th or later. If you have an error and need to run it again within a few days of it being missed, you could switch the job to poll on start, run it once, and turn the option back off without needing to modify any code.

      If you wanted to run it for a specific day you could change the Filename Filter Pattern to ${nameProvider.getName(1)} to force running as if it were the 1st of the month, even if the real date is after the 15th.

      The reason that a JavaAdapter is used here rather than a regular javascript object is because velocity can't invoke javascript functions directly (at least I haven't been able to get them to work.)

      Comment


      • #4
        Thank you for your help.

        Comment

        Working...
        X