From d81a7118827944615c6424bf60b3232031ea631e Mon Sep 17 00:00:00 2001 From: Kaio Magalhaes Date: Tue, 31 Oct 2023 14:11:31 -0300 Subject: [PATCH] add time entries job --- app/services/team_maker_project_creator.rb | 9 ++++----- app/sidekiq/time_entries_job.rb | 9 +++++++++ app/tasks/create_time_entries_task.rb | 11 +++++++++++ config/sidekiq_cron_scheduler.yml | 6 ++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 app/sidekiq/time_entries_job.rb create mode 100644 app/tasks/create_time_entries_task.rb diff --git a/app/services/team_maker_project_creator.rb b/app/services/team_maker_project_creator.rb index b935db2..343b10c 100644 --- a/app/services/team_maker_project_creator.rb +++ b/app/services/team_maker_project_creator.rb @@ -20,9 +20,8 @@ def call def create_time_entires!(team_maker_project_time_entries) team_maker_project_time_entries.each do |time_entry| - next if User.find_by(email: time_entry.resource).nil? - user = User.find_by(email: time_entry.resource) + next if user.nil? TimeEntry.create!( statement_of_work:, @@ -42,11 +41,11 @@ def create_requirements!(team_maker_project_requirements) def create_assignments!(team_maker_project_assignments, requirement) team_maker_project_assignments.each do |assignment| - next if User.find_by(email: assignment.resource).nil? + user = User.find_by(email: assignment.resource) Assignment.create!( requirement:, - user: User.find_by(email: assignment.resource), + user:, start_date: assignment.starts_on, end_date: assignment.ends_on, coverage: assignment.coverage @@ -68,7 +67,7 @@ def professions @professions ||= { 'Engineering' => Profession.find_by(name: 'Engineer'), 'Project Management' => Profession.find_by(name: 'Project Manager'), - 'Designer' => Profession.find_by(name: 'Design') + 'Design' => Profession.find_by(name: 'Designer') } end diff --git a/app/sidekiq/time_entries_job.rb b/app/sidekiq/time_entries_job.rb new file mode 100644 index 0000000..8dbbeeb --- /dev/null +++ b/app/sidekiq/time_entries_job.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class TimeEntriesJob + include Sidekiq::Job + + def perform(*_args) + CreateTimeEntriesTask.create! + end +end diff --git a/app/tasks/create_time_entries_task.rb b/app/tasks/create_time_entries_task.rb new file mode 100644 index 0000000..ffa1dff --- /dev/null +++ b/app/tasks/create_time_entries_task.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreateTimeEntriesTask + def self.create! + projects = Project.all + + projects.each do |project| + TeamMakerProjectCreator.new(project).call + end + end +end diff --git a/config/sidekiq_cron_scheduler.yml b/config/sidekiq_cron_scheduler.yml index cc1fb66..8e36511 100644 --- a/config/sidekiq_cron_scheduler.yml +++ b/config/sidekiq_cron_scheduler.yml @@ -3,3 +3,9 @@ syncronize_issues: cron: "every 1 hour" class: "IssuesJob" queue: default + +syncronize_time_entries: + name: issues_job, # must be uniq! + cron: "every 5 minutes" + class: "TimeEntriesJob" + queue: default