Skip to content

Commit

Permalink
Merge pull request #207 from ImMin5/master
Browse files Browse the repository at this point in the history
Modify scheduler sync parameter
  • Loading branch information
ImMin5 authored Mar 11, 2024
2 parents 21f1e04 + 26a087b commit 4a042f9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def create_task(self) -> list:
return tasks

def _create_trusted_account_sync_task(self):
if datetime.utcnow().hour == 0:
current_hour = datetime.utcnow().hour
if current_hour == 0:
stp = {
"name": "trusted_account_sync_schedule",
"version": "v1",
Expand All @@ -38,7 +39,7 @@ def _create_trusted_account_sync_task(self):
"name": "JobService",
"metadata": {"token": self._token},
"method": "create_jobs_by_trusted_account",
"params": {"params": {"current_hour": datetime.utcnow().hour}},
"params": {"params": {"current_hour": current_hour}},
}
],
}
Expand All @@ -51,6 +52,6 @@ def _create_trusted_account_sync_task(self):
f"{utils.datetime_to_iso8601(datetime.utcnow())} [INFO] [create_task] create_jobs_by_trusted_account => SKIP"
)
print(
f"{utils.datetime_to_iso8601(datetime.utcnow())} [INFO] [create_task] data_source_sync_time: {self._data_source_sync_hour} hour (UTC)"
f"{utils.datetime_to_iso8601(datetime.utcnow())} [INFO] [create_task] data_source_sync_time: {current_hour} hour (UTC)"
)
return []
4 changes: 2 additions & 2 deletions src/spaceone/identity/manager/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def __init__(self, *args, **kwargs):
def create_job(
self,
resource_group: str,
plugin_id: str,
trusted_account_id: str,
domain_id: str,
workspace_id: str,
trusted_account_id: str,
plugin_id: str,
) -> Job:
data = {
"resource_group": resource_group,
Expand Down
1 change: 1 addition & 0 deletions src/spaceone/identity/model/job/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Job(MongoModel):
"job_id",
"trusted_account_id",
"status",
"resource_group",
"created_at",
"finished_at",
],
Expand Down
4 changes: 2 additions & 2 deletions src/spaceone/identity/model/job/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class JobResponse(BaseModel):
job_id: Union[str, None] = None
status: Status
resource_group: ResourceGroup
status: Union[Status, None] = None
resource_group: Union[ResourceGroup, None] = None
trusted_account_id: Union[str, None] = None
plugin_id: Union[str, None] = None
workspace_id: Union[str, None] = None
Expand Down
8 changes: 6 additions & 2 deletions src/spaceone/identity/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def create_jobs_by_trusted_account(self, params):

current_hour = params.get("current_hour", datetime.utcnow().hour)

# todo check provider sync condition
for trusted_account_vo in self._get_all_schedule_enabled_trusted_accounts(
current_hour
):
Expand Down Expand Up @@ -141,7 +142,6 @@ def list(self, params: JobSearchQueryRequest) -> Union[JobsResponse, dict]:
query = params.query or {}

job_vos, total_count = self.job_mgr.list_jobs(query)

jobs_info = [job_vo.to_dict() for job_vo in job_vos]

return JobsResponse(results=jobs_info, total_count=total_count)
Expand Down Expand Up @@ -232,7 +232,11 @@ def created_service_account_job(

# Add Job Options
job_vo = self.job_mgr.create_job(
resource_group, plugin_id, trusted_account_id, workspace_id, domain_id
resource_group,
domain_id,
workspace_id,
trusted_account_id,
plugin_id,
)

if self._check_duplicate_job(domain_id, trusted_account_id, job_vo):
Expand Down

0 comments on commit 4a042f9

Please sign in to comment.